Code Fails at rs.FindFirst

  • Thread starter Thread starter DeVille
  • Start date Start date
D

DeVille

I have this very tricky problem
It relates to three sections of code which I have called
CODE 1, CODE 2 and CODE 3
CODE 1 Returns a record based on the value I select in a
combo box
CODE 2 filters the records based on text I type into a
popup box
CODE 3 deletes the value in my combo box that I used in
CODE 1

My Problem
CODE 1 fails at the line
rs.FindFirst "[LocationID] = " & Str(Nz(Me!
[cboFindLocation], 0))
But only if I have just run the CODE 2
And only since I added the CODE 3 to the database

If anyone can suggest a way to fix this thanks in advance

CODE 1

Private Sub cboFindLocation_AfterUpdate()
' Find the record that matches the control.

If Me.FilterOn Then
Me.FilterOn = False
End If
Dim rs As Object
Set rs = Me.Recordset.Clone

rs.FindFirst "[LocationID] = " & Str(Nz(Me!
[cboFindLocation], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

End Sub

CODE 2

Private Sub LocationButton_Click()
On Error GoTo Err_LocationButton_Click

Dim QryFld As String
Dim CurRecNo As String

Let CurRecNo = Form.CurrentRecord
QryFld = " LocationName "

Me.Filter = "[LocationName] Like '*" & InputBox("Enter
the Name of the Location") & "*'"
Me.FilterOn = True

Exit_LocationButton_Click:
Exit Sub

Err_LocationButton_Click:
MsgBox Err.Description
Resume Exit_LocationButton_Click

End Sub

CODE 3

Private Sub Form_Current()

Me.cboFindLocation = ""

End Sub
 
LocationID is apparently a text field, so you need to enclose its value in
quotes.

Change:

rs.FindFirst "[LocationID] = " & Str(Nz(Me![cboFindLocation], 0))

to:

rs.FindFirst "[LocationID] = """ & Str(Nz(Me![cboFindLocation], 0)) &
""""

Cut & paste directly from this post, so you get the quote marks right.

HTH,
TC
 
Back
Top