amy wrote:
[color=blue]
> Hi Salad:
>
> Thanks for your message. But that didn't solve the problem with
> duplicate records. For example, If there are four Smith in the User_Name
> field, I'd like the ID to be the same for these four records.[/color]
Ahhhh....an important fact you left out. Well, here is what I might do. Do
a Ctrl+C, Ctrl+V and create a copy of the originial (structure and data)
Let's say that the originial table is called Table1. Let's say there are
thow fields; LastName and FirstName. We could create a query of that table
(the originial), sort it on Last name first name and call it Query1.
Please substitute the field/query names with your own. Now add a field to
the original called DUPE, type Text, Len 1
'i'm writing this w/o verifiying. Please compile the sub before running. I
am using DAO
Sub DeleteDuplicates()
Dim rst As DAO.Recordset
Dim strTest As String
set rst = Currentdb.openrecordset("Query1",dbopendynaset)
rst.MoveFirst
Do while not rst.EOF
'first record of a possible dupe is set to N
strTest = NZ(rst![LastName],"") & NZ(rst![FirstName])
rst.Edit
rst!Dupes = "N"
rst.Update
rst.MoveNext
'check if not end of file
If Not rst.EOF Then
'check if we have a duplicate. If the first/last name matches
'the first/last name of the first record of the set, flag as a
dupe
If strTest = NZ(rst![LastName],"") & NZ(rst![FirstName]) then
'yes, we have a duplicate
Do while Not rst.EOF And strTest = NZ(rst![LastName],"") &
NZ(rst![FirstName])
'set all dupes to Y
rst.Edit
rst!Dupes = "Y"
rst.Update
rst.MoveNext
Loop
Endif
Endif
Loop
rst.close
set rst = Nothing
msgbox "All dupes are flagged as Y"
End sub
You can create a new module, cut/copy this code to the module, compile, then
run. Remember to change the query name, lastname, first name to reflect
your table/field names.
Now open up the query (Query1). As you scan down the list you can see the
records the sub flagged as a dupe. If you are satisfied, create a query to
select all records in the table that has Dupe set to Y. Then from the menu
select Query and make it a Delete query. Run it. I suggest you make a
backup copy of the table prior to deleting.
Now you can add the autonumber if you want.
[color=blue]
>
>
> Amy
>
> *** Sent via Developersdex
http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it![/color]