Error 2137

T

T Horner

I am having problems performing a textbox search. I have a textbox that is
filled by a barcode scanner. This is then prased into three separate
textboxes. One of these textboxes(strLot) is used to search my recordset for
matching records.
The combination of the parsing code and the search code is not working right.
If I manually enter the data in strLot, the search works. However when
filled by the VBcode, it gives me run-time error 2137. It tells me I cannot
do a find function here.
I have pasted in my code below.

Private Sub Barcode_AfterUpdate()
If Not IsNull(Me!Barcode) Then
Me!strLot = Left(Me!Barcode, 10)
Me!StrProduct = Mid(Me!Barcode, 11)
Me!strDOM = DateSerial(Mid(Me!Barcode, 2, 2), Mid(Me!Barcode, 4, 2),
Mid(Me!Barcode, 6, 2))
End If

Dim strCodeRef As String
Dim strCode As String

'Check strLot for Null value or Nill Entry first.

If IsNull(Me![strLot]) Or (Me![strLot]) = "" Then
MsgBox "Please enter a value!", vbOKOnly, "Invalid Search Criterion!"
Me![strLot].SetFocus
Exit Sub
End If
'---------------------------------------------------------------

'Performs the search using value entered into strLot
'and evaluates this against values in Lot

DoCmd.ShowAllRecords
DoCmd.GoToControl ("Lot")
DoCmd.FindRecord Me!strLot

code.SetFocus
strCodeRef = Lot.Text
strLot.SetFocus
strCode = strLot.Text

'If matching record found sets focus in Lot
'and clears search control

If strCodeRef = strLot Then
Lot.SetFocus
Barcode = ""

'If value not found sets focus back to Barcode and shows msgbox
Else
MsgBox "Match Not Found For: " & strSearch & " - Please Try
Again.", _
, "Invalid Search Criterion!"
Barcode.SetFocus
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top