I am getting "Type Mismatch Error" when the following code executes. I
am trying to notify the user if she attempts to add a customer with the
same FirstName, LastName, Address(line1) and City as one that already
exists on the file.
If there is a match, ask the user and cancel the record add if she sees
that it's a dup customer.
I had trouble with the line continuations, quotes and continuation
chracters, and noticed that Access added a " on the top line for me.
There are no dimensions for any of these fields; this is the only place
they are used.
' Makes sure the user entered a new customer before saving
Private Sub cmdClose_Click( )
On Error GoTo Err_cmdClose_Cl ick
' to save new cust so they can add garments
Dim lngCustID As Long
' saves the new customer record in tblCustomers
' Makes sure the user entered a new customer before saving
If Me.Dirty = True Then
lngCustID = Me.txtCustID
DoCmd.RunComman d acCmdSaveRecord
' Requery the customer list to see the new customer as well
Forms!frmFindCu stomer.lstCusto mers.Requery
Forms!frmFindCu stomer.lstCusto mers = lngCustID
End If
DoCmd.Close
Exit_cmdClose_C lick:
Exit Sub
Err_cmdClose_Cl ick:
' If the user enters the same first name, last name, street1 and
city as one on file,
' check to see if this is truly a different customer (dup index)
' of if this was an error. Allow save if different; cancel if error
' If response is NOT Yes, Me.undo and get out (recognize it's a
dup-do NOT add)
' If response is YES, add record
If Err.Number = 3022 Then
If MsgBox("Custome r " & Me.txtFirstName & " " &
Me.txtLastName, "" _
& " " & Me.txtAddress1 & " " & Me.txtCity & " exists. "
_
& " Are you sure you want to add this one too?" _
& vbYesNoCancel + vbExclamation, "Duplicate Customer") <>
vbYes Then
Me.Undo
GoTo Exit_cmdClose_C lick
End If
End If
MsgBox Err.Number & " " & Err.Description
Resume Exit_cmdClose_C lick
End Sub
Many thanks.
Sara