Delete All Entries In Recordset ADO
Jan 25, 2012I got a recordset which I get from a database (I use ADO).
I want to delete every entry in that recordset from the database.
I got a recordset which I get from a database (I use ADO).
I want to delete every entry in that recordset from the database.
I found this sample code that works from top to bottom of a spreadsheet. But I need something that will delete the first entry and keep the last entry. My data is sent from one spreadsheet to a Master and sometimes the details can be sent twice, if the responsible person forgets to enter one line of production. The criteria should be the first 5 Columns of the sheet.
Sub Dupe_Killer()
Dim str As String
Dim str2 As String
Dim c As Integer
Dim i As Integer
Application. ScreenUpdating = False
Application.Calculation = xlCalculationManual
Sheets("SAMPLE").Select
rw = Cells(2, 1).End(xlDown).Row
'Sort Data by Date, Location & Number
Range(Cells(1, 1), Cells(1, 14)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Sort Key1:=Cells(1, 1), Order1:=xlAscending, Key2:=Cells(1, 2) _
, Order2:=xlAscending, Key3:=Cells(1, 3), Order3:=xlAscending, Header:= _
xlYes, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _ ....................................
I was wondering if there might be a better way to write this macro. What it does is clears unique items from a Range( leaves duplicates ) I've looked all over the net I can find all kinds of function and subs to remove duplicates but haven't been able to find anything that just removes single entries. I"ll bet there's a more elegant way to write this maybe using a Collection or a Dictionary.
Sub Dummy()
Dim MP1_Rnge As Range
Set MP1_Rnge = Range("A1:A100")
For Each Cell In MP1_Rnge
If Not IsEmpty(Cell) Then
If Cell.Row = 1 Then..........
i am simply asking the macro to delete entries which are less than 5 days old, but it doesnt do it, i dont get any errors either
With Range("A1:J1")
.AutoFilter Field:=6, Criteria1:="
A project for work requires me to write a macro for a set of data that will delete all entries that are above a certain "Margin %" limit. However, different "Product Codes" will have different limits.
Is there a way that I can set up a table of Product Codes and Margin % limits, and have the macro consult the table and delete all entries above the margin limits for the respective product codes?
I have 2 columns of data, apprx. ~25,000 rows.
Col 1 is user IDs and Col 2 is there status (pending, conditional, approved, rejected)
Col1 IDs are not unique because they can have multiple statuses associated with them in Col2. An ID can go from pending to conditional to either approved/rejected and all these are included in the raw data file. I want to remove all duplicate ID rows and keep the ID row with the last known status.
For example:
i have a slight problem i have this script which i want to run on all worksheets which are numbered (i.e. 1,2,3,4 etc) and to delete the rows in the F128 range which is under 00:05:00. I just cant figure it out to get it working.
View 2 Replies View RelatedI have an accounts spreadsheet that I copy and paste customers names and addies into from the website back end sales information.
I do not copy e-mail addresses.
I have a mailto: with an e-mail address appear in the file in lots of places, it seems I delete it from some cells and it appears in others, my file is infested with the things now.
I can delete one by one, but this would take me weeks any ideas of how I can ctrl a select all cells and mass delete these things.
I am face with making a brand new accounts file which is a lot of work.
Here I have a listbox, but I would like to know if it's possible to be able to sort each header on the userform when clicking on the header?
Also, how should I also delete some entries with a button?
listbox.xlsm
I have a very big range of data from B4, to a variable other end from which I would like to delete all entries equal to 0.0000 leaving just those with an entered value.
I guess it's just an if question cycling through the rows and columns? Slight complication is it's on the 3rd sheet of a Workbook, as set out in the sample file.
After this manipulation has been done, I then wish to copy the data from the range B4: end of data into the same cells in the output sheet.
I need a Macro to do the following:
In column A I have a list of Acronyms from A2:A90000 and more
In column B I have the corresponding acronyms spelt out from B2:B90000 and more
When I run the macro, it shoud detect the multiple/duplicate Acronyms and it's corresponding descriptions, DELETE the multiples/duplicates and move the cells up.
Q:How to delete reversal entries?
I have debits & credits in the same excel column and i want to delete the matching amounts but with opposite signs.
Example:
A B
Name Amount
1)Mr. A 2000
2)Mr. B 6000
3)Mr. A -2000
4)Mr. D 4000
5)Mr. A 2000
Now i want to matching amount of Mr. A of row 1 & 3 as these two entries are reversing each other. I am poor in english but hope that i have clarified the problem
I have a UserForm which writes data to rows in a master spreadsheet. I'm attempting to write some vba code for a CommandButton in the master spreadsheet which can identify and delete duplicate entries based on "user ID", "Date", and "Time". I would like the CommandButton to retain the most recent entry from a user and delete all previous entries.
My master sheet is set out as such...
A, B, C, D,
UserID, Date, Time, Response
The users could potentially submit multiple entries on the same day. Ideally I would like to be able to click a CommandButton and delete each user's submission but retain their most recent one (based on "UserID", then "Date", then "Time").
I've searched all day for a solution and I've come close but I can not figure out a code that accounts for my three variables ("UserID", then "Date", then "Time").
Hoping someone would be able to help me with this. I have a sheet (example attached) and this sheet has a number of varying description types in the W coloumn (usually approx 10,000 rows). This field is manually input so there could be spelling mistakes and/or non standard descriptions.
What I would like, if possible, is a macro that would look at the D column and if this is 'GENERAL LEDGER', it would then look at the W column.
An input box would come up, and would list the different descriptions it found in column W, and number them. It would only list each different description once.
e.g.
1. Bank charges
2. Bank charge
3. Cash
4. Fund Custodian Fees
5. Fund Manager fee
6. Interest income cash account
7. Interest income cash acc
8. Miscellaneous expenses
9. Miscellaneous income
10. Other income
11. Sec lending comm
12. Sec lending commission income
13. Tax Reclaimable - Dividends
14. Withholding tax dividend
The user would then be able to type in the corresponding numbers, if possible seperated by a space, comma or semicolon and the macro would then run through the sheet and delete the entire row if D was GENERAL LEDGER and W was the selected description.
i have a created a connection with Access table named Test, the table has 3 fields, ID,Firstname and LastName. The values in field firstName is filled in a Combox which is in Sheet1 of excel sheet.
so far i have done with the coding which create a connection with access table and fille all the firstname from the table to the Combobox using a recordset.
the code for filling combobox value from records set is like
Do Until RecordSet.EOF
shp.ControlFormat.AddItem RecordSet.Fields("Name").Value
RecordSet.MoveNext
Loop
Now what I need is whenever I select a name in a combobox the Cell A1 in excel should show me the LastName for that name.
I am not very sure if we can use offset in this.
i have a select statement, that pulls one row from access and i need to get the data and assign it to different fields in a userform. however, because it only pulls one row, its at .eof and closes, so any following statements cause errors because the recordset is closed.
qc.Open "SELECT * FROM [Equipment_Table] WHERE [Equipment_QC] =" & combobox12.text, cn, adOpenStatic
Equipment_Title.text = qc.fields.item("Equipment_Title")
Equip_File = qc.fields.item("Equipment_File")
Equip_ID = qc.fields.item("Equipment_ID")
I've Created Connectionstring for excel which is in database format and trying to get the data by comparing 2 sheets using he below code.. But not working..
Set ws = Sheet1
sSQL = ""
sSQL = "SELECT [Company Code], "
[Code].....
Currently, my code involves making a connection to a db then run queries. Results from the queries goes to recordset & from the recordset copy to specified range in excel worksheet. I am trying to do an automation process.
The problem is that once the record is pasted in excel worksheet, the date column is not being recognised as date therefore excel function (vlookup) is not giving me the results in my report.
When i do a manual PasteSpecail as CSV into the worksheet from the query result, my report gets populated with data which is correct.
i've tried doing a pastespecial format:="CSV" but it doesnt work.
Is there any codes that i can use to copy from the recordset as a CSV format pastespecial??
Or any other ways that can be done?
I'm getting extremely frustrated with trying to find some code that allows me to paste an ADO recordset into a database table!
What I am doing is on a weekly basis is creating a plan of which containers my company needs to devan. We have a system that stores shipping information about these containers and I get shipping information delivered to me via e-mail from one of our major shipping companies. Their data is more accurate so what I do is paste the data I get from them into my container planning sheet and import it into out Teradata Warehouse to query against using ADO and I import this one record at a time. This is extremely slow!
In order to get around this I want to create a recordset from this data and then paste the recordset into a table in the database. So far this is my ....
I have been creating pivot tables (from the active workbook) with ADO for a while and its working great.
I just tried to switch to DAO and adapted my code accordingly but the new code fail at:
Code: ....
Is there an example outthere that will demonstrate how to create a pivot table using an ADO Recordset? I'll be experimenting tommorow but really don't relish the thought of spending 12 hours trying to figure it out.
View 2 Replies View RelatedWhen I read a CSV file into a recordset, the headers are not all being read. I get gaps in the headers for whatever reason. Attached below is the Function to load the recordset from the file. I have hard coded Hdr to "No" in the connection string.
Code:
Function QueryByID(tableName As String, fieldToQuery As String, Target As Long, Hdr As String) As Recordset
Dim strFilePath, strFileName, strQuery As String
Dim oFSObj, oConn As Object
Dim oRs As Recordset
Dim f, lastRow As Integer
[Code] .......
The below is how I output the resultset:
Code:
Sub OutputResultSet(aTable As String)
Dim row, col, i, j As Integer
row = 1
col = 1
ThisWorkbook.Sheets(aTable).Activate
[Code] .....
I have triple checked the CSV file and the first row in each file has definitely got headers. Some headers are loaded and output fine, others are just blank.
I want to fill a listbox with values from a database.
The query et al. works just fine, but I cant get the listbox filled.
Is there a command to fill the listbox with all the entries in the recordset at once?
I have a sub-routine I call on that takes a current recordset and converts it to an Array.
I would like to make this sub-routine tool more flexable by being able to specify THE NAMES for the recordset and an array involved.
For example
Sub My_Code()
....blal bla bla.... current code...
Call Recordset_To_Array( Recordset_name, Array_name )
....bla bla bla... continued
end sub
And the subroutine tool:
Sub Recordset_To_Array( Recordset_name as String, Array_name as string )
'Code that generates RS
'Need to take Recordset_name string value and use it in the line below at "XXXXX"
Dim XXXXX as Recordset
'Code that generates array
'Need to take Array_name string value and use it in the line below at "XXXXX"
Dim XXXXX as Variant
End Sub
how i can display different values using the Selection.FormulaArray, ok look at my
Dim mySheet As Worksheet
' On Error GoTo errors
Dim x As Integer
x = TextBox1.Text
Dim y As Integer
y = RefEdit2.value
Set mySheet = Excel.ActiveSheet
mySheet. Range(RefEdit1).Select
Selection.FormulaArray = "=multiplie_value(""" & x & """, """ & y & """)"
MsgBox Selection.FormulaArray
Now the function i call:
Public Function multiplie_value(valor As Integer, multiplo As Integer) As Integer
multiplie_value = Val(valor) * multiplo
End Function
thats an example. so the real question is i create a form, the user enter some values to search to a database, the user select an area(a range) where they want the data to be display, but i dont how to display that info that is coming from the database in the range that the user selected. The info displayed in the range should look like a tabular report, column headers, etc.
I have a function that loops through sheets and opens a query and copys the information to a sheet. I have gone in the access db and updated the query. Yet everytime i call it in excel it returns the old data. I have gone into access and verified what data I should get and I just don't get it.
I pass in the query name and the sheet name into qryName and sheetName name.
Code:
Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim sQRY As String
Dim strFilePath As String
[Code].....
I am trying to run a prestored query in a Access database and popuate the result into a Recordset --- through Excel. So far, I have managed to accomplish that using the code below. However, now I need to update some records in the recordset. The code below does not allow me to do so.
The following message prompted when the code tried to update the record: Run-time error '3251' Current Recordset does not support updating. This may be a limitation of the provider, or of the selected locktype.
This is written for other users who only knows how to create a query in Access. And the users prefer not to import the query results to spreadsheet.
*Someone suggested use Recordset.Open however, that seems to work only with SQL statement but not prestored Queries.
Code:
Sub RunExistingQuery()
'Execute prestored queries in Access
Dim Con As ADODB.Connection
[Code].....
I'm looking for an example of creating a pivot table based on an ADO Access Recordset.
I understand I can use MS Query - which I am, but looking to see if an alternative exists. A table I am inetrested in currently has 400,000 records I would like to retrieve and pivot.
I am trying to populate a 3 column listbox in a userform from SQL Server via ADO. When the result set consists of more than one record, there is no problem and the data is displayed properly (ie each piece of data is in its appropriate column) eg...
StockCode..........QtyReqd.........JobDeliveryDate
test1...................1................. 01/01/1900
test2...................1..................31/12/1900
test3...................3..................18/02/1900
however when the recordset returns only a single record, the data does not transpose and views as below (ie each piece of data in the record is on a different line in the first column
StockCode...........QtyReqd.........JobDeliveryDate
test1
1
01/01/1900
I am having trouble setting up a query for a recordset that will list duplicates for an automated process to clean up. I am using Excel 2010 with Microsoft ActiveX Data Objects Recordset 6.0 Library and Microsoft ActiveX Data Objects 6.1 Library as references.
So far, I have chopped the query down to it's most basic elements and reassembled until it broke. Necessary pieces work well, but when I combine them, I get nowhere.
Here is the working simple query to retrieve a single row:
Code:
dupeSQL = "SELECT PSID FROM [Obstructed$] "
Here is the working single query to retrieve a count:
Code:
dupeSQL = "SELECT COUNT(PSID) As '" & "CountPSID" & "' " _
& "FROM [Obstructed$] "
When combined, I cannot figure out why it won't work:
Code:
dupeSQL = "SELECT [PSID], COUNT(PSID) As '" & "CountPSID" & "' " _
& "FROM [Obstructed$] "
Here is what I am trying to get to:
Code:
dupeSQL = "SELECT [PSID], COUNT(PSID) As '" & "CountPSID" & "' " _
& "FROM [Obstructed$] " _
& "WHERE COUNT(PSID) > 1 " _
& "GROUP BY PSID"
I can even work without the GROUP BY. I have also played with the HAVING clause to try and accommodate the [PSID] field, but have gotten nowhere.