Hello all,
What I'm attempting to do with the following code is prevent duplicate records from being entered in our customers records. I'm checking several fields using dlookup to see if I have a match, if I do then I would like to fire a message letting the users know that we have a matching record and then move them to the record that matches. The code below is a test code so I haven't finished everything I'm just trying to see if it will work. Everything does except for moving to the matching record and I think it's because I don't know the proper syntax to make it go. I know varID is finding the right customersID cause I had it fill a dummy text box and the right ID was there. Could someone please lend a hand. Thanks ahead of time and here's the code that I've played with so far.
Shane
Dim varPhone As Variant
varPhone = Nz(DLookup("Phone", "Customers", "Phone = Forms![frmCustomers]![Phone]"
, 0)
Dim varLName As Variant
varLName = Nz(DLookup("LastName", "Customers", "LastName = Forms![frmCustomers]![LastName]"
, 0)
Dim varFName As Variant
varFName = Nz(DLookup("FirstName", "Customers", "FirstName = Forms![frmCustomers]![FirstName]"
, 0)
If Me.Phone = varPhone Then
MsgBox "This worked"
Dim varID As Variant
varID = DLookup("CustomersID", "Customers", "Phone = Forms![frmCustomers]![Phone]"
Dim rst As Recordset, strCriteria As String
strCriteria = "[CustomersID]=" & varID
Set rst = Me.RecordsetClone
rst.FindFirst strCriteria
If rst.NoMatch Then
MsgBox "No entry found"
Else
Me.Bookmark = rst.Bookmark
End If
End If
This message keeps telling me "No entry found"
What I'm attempting to do with the following code is prevent duplicate records from being entered in our customers records. I'm checking several fields using dlookup to see if I have a match, if I do then I would like to fire a message letting the users know that we have a matching record and then move them to the record that matches. The code below is a test code so I haven't finished everything I'm just trying to see if it will work. Everything does except for moving to the matching record and I think it's because I don't know the proper syntax to make it go. I know varID is finding the right customersID cause I had it fill a dummy text box and the right ID was there. Could someone please lend a hand. Thanks ahead of time and here's the code that I've played with so far.
Shane
Dim varPhone As Variant
varPhone = Nz(DLookup("Phone", "Customers", "Phone = Forms![frmCustomers]![Phone]"
Dim varLName As Variant
varLName = Nz(DLookup("LastName", "Customers", "LastName = Forms![frmCustomers]![LastName]"
Dim varFName As Variant
varFName = Nz(DLookup("FirstName", "Customers", "FirstName = Forms![frmCustomers]![FirstName]"
If Me.Phone = varPhone Then
MsgBox "This worked"
Dim varID As Variant
varID = DLookup("CustomersID", "Customers", "Phone = Forms![frmCustomers]![Phone]"
Dim rst As Recordset, strCriteria As String
strCriteria = "[CustomersID]=" & varID
Set rst = Me.RecordsetClone
rst.FindFirst strCriteria
If rst.NoMatch Then
MsgBox "No entry found"
Else
Me.Bookmark = rst.Bookmark
End If
End If
This message keeps telling me "No entry found"