Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MoveNext syntax problems (I think)

Status
Not open for further replies.

Sullaway

Technical User
Sep 27, 2000
50
0
0
US
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"


 
I thought I might explain what I'm attempting to do so that maybe the above will make better sense.

What I would like some advise on how to do is. When a user is entering info on a new customer and has started a NEW record in frmCustomers I would like to use the Name field and Phone field to see if this customer already exists. If they do, I would like to pop a message up informing the user that the customer already exists and then take them to the matching record that was found and exit the new record in frmCustomers without saving it.

If someone could point me in the right direction and maybe even provide some examples of code (if that's not too much to ask) I would really appreciate it. I almost have it working but there's something about it being a new record that it won't take me to the matching record.

Thanks for any and all help,
Shane


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top