|
-
Jul 23rd, 2012, 03:19 PM
#1
Thread Starter
Junior Member
Deduping in VBA using an ID field???
This is what i have so far:
Code:
CntTblSQL = "SELECT sorted.LOC_ID, Count(sorted.LOC_ID) AS CountOfLOC_ID INTO CntTable FROM sorted GROUP BY sorted.LOC_ID ORDER BY sorted.LOC_ID;"
DoCmd.SetWarnings False
DoCmd.RunSQL CntTblSQL
DoCmd.SetWarnings True
pass1 = "SELECT * FROM CntTable"
dataconnect.Open pass1, CurrentProject.Connection, adOpenDynamic, adLockOptimistic
With dataconnect
Do While Not dataconnect.EOF
strLocId = dataconnect.Fields("LOC_ID").Value
Count = dataconnect.Fields("CountofLOC_ID").Value
MsgBox strLocId
MsgBox Count
.MoveNext
Loop
End With
dataconnect.Close
End Sub
I have no idea which way to go next, basically i have a field called "LOC_ID" that has a bunch of duplicates in it. I need to select one of each variation using the "LOC_ID" field while still keeping all the other fields in the record.
any help would be much appreciated!
Last edited by Siddharth Rout; Jul 23rd, 2012 at 04:32 PM.
Reason: Added Code Tags
-
Jul 23rd, 2012, 03:39 PM
#2
Re: Deduping in VBA using an ID field???
Welcome to VBForums 
Thread moved from the 'VB.Net' forum to the 'Office Development/VBA' forum.
-
Jul 23rd, 2012, 11:10 PM
#3
Hyperactive Member
Re: Deduping in VBA using an ID field???
When the LOC_ID is duplicated, are all the other fields dupicated too, or do they have different data?
e.g. for (LOC_ID, Otherfield1, Otherfield2)
Is it:-
1 ,Blah, Rhubarb
1, Blah, Rhubarb
Or:-
1, Blah, Rhubarb
1, Blah, Yada-Yada
If they are the same you can GROUP BY (in your SQL) the other fields to lose the dupes.
If they are different you need some logic to define which of the records is the correct one.
-
Jul 24th, 2012, 10:12 AM
#4
Thread Starter
Junior Member
Re: Deduping in VBA using an ID field???
They have different data. Basically I need to select one of each different LOC_ID, but the remaining fields need to be be kept as is. I have about 70,000 records and only 101 different variations of LOC_ID, so eventually I will wind up with only 101 records left, each having a different LOC_ID.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|