Go to existing record after search

tscotti

Registered User.
Local time
Today, 14:05
Joined
Aug 15, 2004
Messages
47
Hello All,

Below is the code that I use for searching an existing record in a form after entering the "ProductNo":

Private Sub ProductNo_BeforeUpdate(Cancel As Integer)
Dim varX As Variant
varX = DLookup("[ProductNo]", "tbLProducts", "[ProductNo] = '" & Forms!frmProducts.[ProductNo] & "'")
If Not IsNull(varX) Then
MsgBox [ProductNo].Value & " already exists as a product number"
Me.Undo
Cancel = True

Else
'do nothing!
End If
End Sub

My question is...After the message, how can I have Access go to the existing record in the same form?

Thanks, in advance, for responding.

Tony
 
Not sure which form you mean by "same form", but one of these might do...
Code:
Me.Recordset.FindFirst "ProductNo = " & varX
...or...
Forms("frmProducts").Recordset.FindFirst "ProductNo = " & varX
 
Lagbolt,

Thanks for replying.

I'm getting a "data type mismatch" on both of your expressions.

Any ideas why?

Thanks.

Tony
 
Your ProductNo is a string.
Code:
Me.Recordset.FindFirst "ProductNo = '" & varX & "'"
Cheers,
Mark
 

Users who are viewing this thread

Back
Top Bottom