Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Urgent! Help with de-duplication.

Status
Not open for further replies.

steverbs

Programmer
Jul 17, 2003
253
GB
Hey all.

I have just been put in a nasty situation by my boss lady and could really do with some help. One of the many things that I need to do is to finish off a de-duplication thingy in VBA, which I am still not that familiar with. Here is the code so far:

Set theList = Me.lstPossibleDuplicates
c = 0
For Each varItem In theList.ItemsSelected
If c = 0 Then
sql = "SELECT Contacts.* FROM Contacts WHERE Contact_ID = " & varItem & ";"
Set rsMasterContact = CurrentDb.OpenRecordset(sql)
Else
sql = "SELECT Contacts.* FROM Contacts WHERE Contact_ID = " & varItem & ";"
Set rsSubContact = CurrentDb.OpenRecordset(sql)
End If
c = c + 1
Next

For i = 0 To rsMasterContact.Fields.Count
If IsNull(rsMasterContact.Fields(i)) And Not IsNull(rsSubContact.Fields(i)) Then
rsMasterContact.Edit
rsMasterContact.Fields(i) = rsSubContact.Fields(i)
rsMasterContact.Update
End If
Next
rsSubContact.Close
rsMasterContact.Close

Basically, it is getting two selected items (there will only ever be two items in the list) from a list box (to get the row ID's) and is trying to merge the duplicates, but I keep getting an error message about the "For i=0 To RsMaster...". Am I on the right track here? If so, how do I sort this out? If not, what should I be doing?

Please help and I'll buy you a drink :p

Steve.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top