Create a message box to avoid duplicate records

J

Jay

Hello,
I am trying to create a message box to avoid creating duplicate records. I
have already change the field to be the table's primary key, but the user
will not be notified as the record being a duplicate until he/she finishes
filling out the form. I am trying to have a message box appear after they
enter the field 'cboglobalID' if duplicate. I tried using the following code
but I am getting an error message that takes me back to (If
DCount("PARTICIPANTGLOBALID", "tbl_QuotaStatusTracker", stLinkCriteria) > 0
Then). I cannot figure out what is that I am doing wrong. Please help. Thank
you

Private Sub cboGlobalID_BeforeUpdate(Cancel As Integer)

Dim SID As String
Dim stLinkCriteria As String
Dim rsc As DAO.Recordset

Set rsc = Me.RecordsetClone

SID = Me.cboGlobalID.Value
stLinkCriteria = "[cboGlobalID]=" & "'" & SID & "'"

'Check StudentDetails table for duplicate PARTICIPANTGLOBALID
If DCount("PARTICIPANTGLOBALID", "tbl_QuotaStatusTracker",
stLinkCriteria) > 0 Then
'Undo duplicate entry
Me.Undo
'Message box warning of duplication
MsgBox "Warning Participant Global ID " _
& SID & " has already been entered." _

End If

Set rsc = Nothing
End Sub
 
Top