Rob said:
John Nurick wrote:
PMFJI
Wouldn't it be simpler not to create the duplicates in the first place?
E.g. using an append query like this:
INSERT INTO HoldInfo SELECT * FROM MenuInfo
WHERE MenuInfo.XXX NOT IN (SELECT XXX FROM HoldInfo);
(XXX being a field that you can use to identify duplicates)
It doesn't matter since they are both the same...maybe I can run a
duplicate query and then a delete query that would run one less than the
number of duplicates, but how would I set this up?
Thanks
DS
--
John Nurick [Microsoft Access MVP]
Please respond in the newgroup and not by email.
I suppose your right. But the problem is I'm not just copying one
record. I'm copying many records and there might be more than oe set of
duplicates, this is where its even more confusing.
Thanks
DS
As John says, it'd be better to avoid the creation of duplicates in the
first place, but if you really have to do it in the way you suggest then it
would be something like:
Create a grouped query, grouping by all the fields that will actually be
duplicated, but with the PK (if you don't have one, add it) set to min (or
max, in fact) - this will just give you the PK fields for the record that
you are going to keep.
Write a delete query that deletes any records with PK values that don't
appear in the first query (...not straightforward, shout if you need help
with how to do that)
Boy this is getting complicated, I've been scouring the net and it seems
that a lot of people want to delete duplicate fields but keep just one.
I put this together but it deletes everything....I was trying to get it
to loop on the NumberofDups field where it would delete all and the stop
at one.
Private Sub Command2_Click()
With Me.List0
.RowSource = "SELECT First(MenuInfo.MenuID) AS [MenuID Field], " & _
"First(MenuInfo.MenuCatID) AS [MenuCatID Field], " & _
"First(MenuInfo.ItemID) AS [ItemID Field], " & _
"First(MenuInfo.ModCatID) AS [ModCatID Field], " & _
"First(MenuInfo.ModID) AS [ModID Field], " & _
"First(MenuInfo.AttachID) AS [AttachID Field], " & _
"First(MenuInfo.AttModCatID) AS [AttModCatID Field], " & _
"First(MenuInfo.AttachModID) AS [AttachModID Field], " & _
"Count(MenuInfo.MenuID) AS NumberOfDups " & _
"FROM MenuInfo " & _
"GROUP BY MenuInfo.MenuID, MenuInfo.MenuCatID, " & _
"MenuInfo.ItemID, MenuInfo.ModCatID, MenuInfo.ModID, " & _
"MenuInfo.AttachID, MenuInfo.AttModCatID, MenuInfo.AttachModID " & _
"HAVING (((Count(MenuInfo.MenuID))>1) " & _
"AND ((Count(MenuInfo.AttachModID))>1));"
.Requery
End With
Dim Dupe As Integer
For Dupe = 1 To Nz([NumberOfDups] - 1, 0)
DoCmd.SetWarnings False
Dim DupeSQL As String
DupeSQL = "DELETE * FROM MenuInfo "
DoCmd.RunSQL (DupeSQL)
DoCmd.SetWarnings True
Next Dupe
End Sub
Any help apprciated.
Thanks
DS