Check Name for New entry

O

Octavee Uhl

What is the best way for checking if there is already an
entry for First and Lastname in the Database? I want have
the option to save the same name, but there should be a
message etc. that gives me a warning. I use access 2000.
 
W

Wayne Morgan

In the BeforeUpdate event of the form, you could use DCount to see if there
are already records that match your criteria. If there are, then DCount will
be >=1, if not then DCount will be 0.

If DCount("*", "tblMyTable", "[FirstName]='" & Me.txtFirstName & "' And
[LastName]=""" & Me.txtLastName & """") .=1 Then
If Msgbox("There is already someone by that name. Continue?",
vbYesNo+vbQuestion, "Duplicate Name") = vbNo Then
Cancel = True
End If
End If

I used the doubled-up double quotes instead of single quotes for the last
name because a last name with an apostrophe (i.e. O'Hare) will cause
problems if you use the single quote. Also, this won't catch misspelled
names.
 

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