duplicates notification

D

DavdB

Is there a way that I can have a field in a form notify
me if there are any duplicates, but still allow them?
 
D

Denny G.

Yes, be sure that duplicates are allowed for the field in
its table and add the following code in the After Update
event for the field in your form:

Private Sub Title_AfterUpdate()
On Error GoTo Err_Title_AfterUpdate
If DCount
("[YourDataField]", "[YourQueryOrTableName]", "[YourDataFi
eld]=Forms!frmYourFormName![YourDataField]") <> 0 Then
Beep
MsgBox "Duplicate thing! Change the thing name or
click on the UNDO button" _
& " and enter an different thing.",
16, "Duplicate thing"
End If

Exit_Title_AfterUpdate:
Exit Sub

Err_Title_AfterUpdate:
MsgBox Error$
Resume Exit_Title_AfterUpdate

End Sub

HTH, Denny G.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top