J
joecosmides
Hello all and thank you for any replies. I have a Table named
"CustomerT" and a customer form that has a field in it called "Phone".
The CustomerT has a field called "CustomerID" and that is the primary
key and an autonumber. Our sales people love to enter in a new
customer without searching to see if that customer already exists. We
have the "Phone" field in the CustomerT table set to not allow
duplicate data but it will allow Null data. I need to have some Before
Update code that will use Dlookup or Dcount to see if the phone number
already exists in another record and if so it will not save any data
that they have already enterd into the form and will pop up a message
telling them that another records exists with that phone number and
then ask them if they would like to open that existing record. This is
the code I have so far but I can't figure out how to get it to open
the exisiting (original record) and I also need to make sure it does
not error if the phone number field is left blank. In other words, if
you start typing into the phone field and then erase what you just put
in, the code I am about to paste here will pop an error and debug.
Dim SID As String
Dim stLinkCriteria As String
Dim rsc As DAO.Recordset
Set rsc = Me.RecordsetClone
SID = Me.Phone.Value
stLinkCriteria = "[Phone]=" & "'" & SID & "'"
If DCount("Phone", "CustomerT", _
stLinkCriteria) > 0 Then
'Undo duplicate entry
Me.Undo
'Message box warning of duplication
MsgBox "Warning Phone Number " _
& SID & " already exists." _
& vbCr & vbCr & "You will now been taken to the record.",
_
vbInformation, "Duplicate Information"
'Go to record of original phone number
rsc.FindFirst stLinkCriteria
Me.Bookmark = rsc.Bookmark
End If
Set rsc = Nothing
"CustomerT" and a customer form that has a field in it called "Phone".
The CustomerT has a field called "CustomerID" and that is the primary
key and an autonumber. Our sales people love to enter in a new
customer without searching to see if that customer already exists. We
have the "Phone" field in the CustomerT table set to not allow
duplicate data but it will allow Null data. I need to have some Before
Update code that will use Dlookup or Dcount to see if the phone number
already exists in another record and if so it will not save any data
that they have already enterd into the form and will pop up a message
telling them that another records exists with that phone number and
then ask them if they would like to open that existing record. This is
the code I have so far but I can't figure out how to get it to open
the exisiting (original record) and I also need to make sure it does
not error if the phone number field is left blank. In other words, if
you start typing into the phone field and then erase what you just put
in, the code I am about to paste here will pop an error and debug.
Dim SID As String
Dim stLinkCriteria As String
Dim rsc As DAO.Recordset
Set rsc = Me.RecordsetClone
SID = Me.Phone.Value
stLinkCriteria = "[Phone]=" & "'" & SID & "'"
If DCount("Phone", "CustomerT", _
stLinkCriteria) > 0 Then
'Undo duplicate entry
Me.Undo
'Message box warning of duplication
MsgBox "Warning Phone Number " _
& SID & " already exists." _
& vbCr & vbCr & "You will now been taken to the record.",
_
vbInformation, "Duplicate Information"
'Go to record of original phone number
rsc.FindFirst stLinkCriteria
Me.Bookmark = rsc.Bookmark
End If
Set rsc = Nothing