S
Steven M. Britton
I have a button that runs an append query, it adds to an
Orders table (Similar to Northwind), and the OrderID
(AutoNumber) is the primary Key. But if the user clicks
the button twice or three times it adds the records again
and again. I can't change the primary key though because
it is related to the Order_Detail via that ID.
What should I do to prevent adding duplicate data?
This is what I currently have, but it doesn't work at
all... I am new at this to any help would be great!!!
Private Sub btnAppendOrders_Click()
On Error GoTo Err_btnAppendOrders_Click
'Check for duplicates
Form.Filter = tblOrders.CCNumber <>
qryAppendOrders.CCNumber
Form.FilterOn = True
If Form.RecordSource.RecordCount = 0 Then
'Append Orders
Dim stDocName As String
stDocName = "qryAppendOrders"
DoCmd.OpenQuery stDocName, acNormal, acEdit
Exit_Command0_Click:
Exit Sub
Err_Command0_Click:
MsgBox Err.Description
Resume Exit_Command0_Click
End If
End Sub
Orders table (Similar to Northwind), and the OrderID
(AutoNumber) is the primary Key. But if the user clicks
the button twice or three times it adds the records again
and again. I can't change the primary key though because
it is related to the Order_Detail via that ID.
What should I do to prevent adding duplicate data?
This is what I currently have, but it doesn't work at
all... I am new at this to any help would be great!!!
Private Sub btnAppendOrders_Click()
On Error GoTo Err_btnAppendOrders_Click
'Check for duplicates
Form.Filter = tblOrders.CCNumber <>
qryAppendOrders.CCNumber
Form.FilterOn = True
If Form.RecordSource.RecordCount = 0 Then
'Append Orders
Dim stDocName As String
stDocName = "qryAppendOrders"
DoCmd.OpenQuery stDocName, acNormal, acEdit
Exit_Command0_Click:
Exit Sub
Err_Command0_Click:
MsgBox Err.Description
Resume Exit_Command0_Click
End If
End Sub