Message Box if Duplicate Customer Name

  • Thread starter Thread starter Nicholas
  • Start date Start date
N

Nicholas

Hi

Dose anyone have a piece of code to help prevent the same
name getting entered in my Customers table

I have two fields 'FirstName' and 'LastName' I would like
a piece of code to attach to the after update event of
the 'LastName' field that basically checks if there is
another record with both the same 'LastName' and the
same 'FirstName' as the record that is just being created
in the Customers Detail form 'frmCustomerDetails'. I want
to still allow the user to enter a customer with the same
name but just flash up a message box that warns them a
person with the exact same name is already recorded in
the Customer details table 'tblCustomerDetails'.

If anyone can help thanks in advance

Private Sub LastName_AfterUpdate()

IF ???????????????

End Sub
 
On the AfterUpdate event of the LastName control:

Private Sub LastName_AfterUpdate()
If DCount("*", "tblCustomerDetails", "LastName='" & [LastName] & _
"' And [FirstName]='" & [FirstName] & "'") > 0 Then
MsgBox "The database already contains a record for a person " & _
"with the same first and last names."
End If
End Sub
 
THANKS
-----Original Message-----
On the AfterUpdate event of the LastName control:

Private Sub LastName_AfterUpdate()
If DCount("*", "tblCustomerDetails", "LastName='" & [LastName] & _
"' And [FirstName]='" & [FirstName] & "'") > 0 Then
MsgBox "The database already contains a record for a person " & _
"with the same first and last names."
End If
End Sub


--

Ken Snell
<MS ACCESS MVP>

Hi

Dose anyone have a piece of code to help prevent the same
name getting entered in my Customers table

I have two fields 'FirstName' and 'LastName' I would like
a piece of code to attach to the after update event of
the 'LastName' field that basically checks if there is
another record with both the same 'LastName' and the
same 'FirstName' as the record that is just being created
in the Customers Detail form 'frmCustomerDetails'. I want
to still allow the user to enter a customer with the same
name but just flash up a message box that warns them a
person with the exact same name is already recorded in
the Customer details table 'tblCustomerDetails'.

If anyone can help thanks in advance

Private Sub LastName_AfterUpdate()

IF ???????????????

End Sub


.
 
Back
Top