Viewing Duplicates on a form
I have a form in Access 2K. I would like to type in a Lname to check for duplicate records.
If there are any duplicates have access return a list that I can select from or at least show them on a list.
Web Development
I have a form in Access 2K. I would like to type in a Lname to check for duplicate records.
If there are any duplicates have access return a list that I can select from or at least show them on a list.
by john_wills
by djpinson
by shanghai sam
Try the following:
---Start Code---
Dim dbs as Database
Dim rst as recordset
set dbs = Currentdb
set rst = dbs.OpenRecordset("SELECT RecordID FROM tblNames WHERE LName = '" & txtLName & '")
if rst.RecordCount = 0 then
msgbox "No duplicates exist"
set rst = nothing
set dbs = nothing
exit sub
endif
-- comments
' If your code continues, then do something with the recordset that now contains your duplicates. I am putting their RecordIDs that I asked for in the SELECT statement) into a message box, but you could ask for other fields and put them into a list box or another form etc
--- code continues
Dim x as integer
Dim strDuplicates as string
x = 0
rst.movelast
rst.movefirst
strDuplicates = ""
strDuplicates = rst.fields!(RecordID)
rst.movenext
x = x + 1
while (x < rst.recordcount)
strDuplicates = ", " & rst.fields!(RecordID)
rst.movenext
x = x + 1
Wend
msgbox strDuplicates, vbokonly, "Duplicates Found"
set rst = nothing
set dbs = nothing
---End Code---
This is just off the top of my head, so check the syntax and while code etc
Hope it helps
by djpinson
by timfox
Perhaps I will have to add a sig to my posts...
I was answer 2, above.
cheers, all
TF
by djpinson
by djpinson
This discussion is closed to new replies.
Sort by Trending