Search Text Box

  • Thread starter Debbie Wend via AccessMonster.com
  • Start date
D

Debbie Wend via AccessMonster.com

I have a text box to type the name or a number for a search to find the
record. The number search is working but NOT the word search. Below is my
code:


Private Sub TextJO_AfterUpdate()
Dim rs As Object
Set rs = Me.RecordsetClone
If Val(Me.TextJO) = 0 Then
'They typed a name
'(Name Search code goes here)
rs.FindFirst "TempName = ' " & [TextJO] & " ' "
Me.Bookmark = rs.Bookmark
Else
'They typed TrackingNo
'(Number Search code goes here)
rs.FindFirst "[TrackingNo] = " & Str(Nz(Me![TextJO], 0))
Me.Bookmark = rs.Bookmark
End If

End Sub

Thanks
Debbie
 
S

SteveS

Debbie said:
I have a text box to type the name or a number for a search to find the
record. The number search is working but NOT the word search. Below is my
code:


Private Sub TextJO_AfterUpdate()
Dim rs As Object
Set rs = Me.RecordsetClone
If Val(Me.TextJO) = 0 Then
'They typed a name
'(Name Search code goes here)
rs.FindFirst "TempName = ' " & [TextJO] & " ' "
Me.Bookmark = rs.Bookmark
Else
'They typed TrackingNo
'(Number Search code goes here)
rs.FindFirst "[TrackingNo] = " & Str(Nz(Me![TextJO], 0))
Me.Bookmark = rs.Bookmark
End If

End Sub

Thanks
Debbie

Debbie,

You had an extra spaces before and after quotes.

Also, why are you taking a number and converting it to a string in the number
search part??

Here is your code (with a little extra checking)

'*** begin code *****
Private Sub TextJO_AfterUpdate()
Dim rs As Object
Set rs = Me.RecordsetClone
If Val(Me.TextJO) = 0 Then
'They typed a name
'(Name Search code goes here)
' removed spaces here \/ and here \/
rs.FindFirst "TempName = '" & Me.TextJO & "'"
' check if found
If Not rs.NoMatch Then
Me.Bookmark = rs.Bookmark
Else
MsgBox "Text not found"
End If
Else
'They typed TrackingNo
'(Number Search code goes here)
'str() function not needed \/
rs.FindFirst "[TrackingNo] = " & Nz(Me![TextJO], 0)
' check if found
If Not rs.NoMatch Then
Me.Bookmark = rs.Bookmark
Else
MsgBox "Tracking Number not found"
End If
End If

' clean up!!
rs.Close
Set rs = Nothing
End Sub
'*** end code ****

HTH
 

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