Code Start for Record Update

VBABasix

Board Regular
Joined
Aug 15, 2005
Messages
52
I am trying to loop through a table to identify records that have more than 1 customer number. And then update the Equip_id field in the table to a unique id. The first step that I was trying was simply opening the record set and checking for the match. Below if the code that I am using. The error message that I am getting is a type mismatch.

Private Sub Next_rec_Click()
Dim db As Database
Dim rs As Recordset
Dim ris As Long
Dim StrSQL As String

Set db = CurrentDb

StrSQL = "Select * from Td_Order;"

Set rs = db.OpenRecordset(StrSQL)

rs.MoveLast
rs.MoveFirst

Do While Not rst.EOF
rcdOne = rs!Sold_to
rs.MoveNext
rcdTwo = rs!Sold_to
If rcdOne = rcdTwo Then
MsgBox "I made it this far"

rst.MovePrevious
End If
Loop
End Sub

Would appreciate any help. Error occurs on the set rs line.

Thanks,

Chris
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Chris, try changing this...
Code:
Private Sub Next_rec_Click()
Dim db As Database
Dim rs As Recordset
Dim ris As Long
Dim StrSQL As String

Set db = CurrentDb

StrSQL = "Select * from Td_Order;"

Set rs = db.OpenRecordset(StrSQL)
To this...
Code:
Private Sub Next_rec_Click()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim qdf As DAO.QueryDef
Dim ris As Long
Dim StrSQL As String

Set db = CurrentDb

StrSQL = "Select * from Td_Order;"

Set qdf = db.CreateQueryDef("",StrSQL)

Set rs = qdf.OpenRecordset
Denis
 
Upvote 0
maybe I'm missunderstanding the problem but why not utilize the database to find your dupes? Access has a find duplicates query wizard.
 
Upvote 0
Thanks for the help. I was actually able to do this through a query after re-designing the table structures.

Chris
 
Upvote 0

Forum statistics

Threads
1,214,784
Messages
6,121,536
Members
449,037
Latest member
tmmotairi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top