In the BeforeUpdate event of the *primary key control (or controls)* try
something like the
following:
Private Sub Custid_BeforeUpdate(Cancel As Integer)
if not isnull(dlookup("Custid","myTable","Custid=" & me.Custid)) then
msgbox "Record Already exists!"
cancel=true
endif
End Sub
The Dlookup will return a null if there is no match so you are looking
for a Not null condition to indicate a duplicate. If any of your
fields are text you will have to wrap the value in Quotes so that the
value is passed to the Dlookup as a literal string. There are many
posts in this newsgroup that describe how to do this if you aren't
sure - or post again and I'll give you the syntax.
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.