Check Name for New entry

  • Thread starter Thread starter Octavee Uhl
  • Start date Start date
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.
 
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.
 
Back
Top