Can you use Like when talking about Tables?

Saint34

Registered User.
Local time
Today, 08:41
Joined
Jun 23, 2010
Messages
16
Hello I am new to MS Access but I am learning, I pick up quick.

My question is can you use a wildcard search when looking for a recordset on a continuous form thats attached to a table? I know i probly should be creating a Quary then searching then pulling that information up but i was unsure how to do that.

Heres what i have done so far
There is a textbox called SearchField that the user can enter something in
There is a search button, once the user hits the search it runs the following code:

Private Sub Search_Click()

Me.Form.RecordsetClone.FindFirst "PN = '" & Me.SearchField.Value & "'"
If Not Me.Form.RecordsetClone.NoMatch Then
Me.Form.Bookmark = Me.Form.RecordsetClone.Bookmark
Else
MsgBox " Part number not found"
End If
End Sub

This code works (Searches for what is in the SearchField textbox and looks for it in the PN collumn of the table, then it will select it if it exists) This ONLY works if the PN is exactly how you type it in however I would like it if you could type 15* and it would find anything that starts with 15.

Please help.
 
the find first is search for an entire match

try clicking a control in your form, then usig the binoculars to search for stuff. you can set the search there to "any part of field"
 
The Find methods should work just exactly like a SQL WHERE clause so you'd just create LIKE in same way:

Code:
Me.Form.RecordsetClone.FindFirst "PN LIKE '" & Me.SearchField.Value & "*'"

HTH.
 
That worked perfect! I tried doing it however I must have had my syntax wrong. Would you know any good places for syntax instructions or maybe a bunch of examples? VBA seems to have terrible syntax with all the "'" & ______ & "'"

Thanks again!

-Saint
 
That worked perfect! I tried doing it however

Which is it? It worked perfect or not. The "PN LIKE" should work, well, perfect. As far as the VB syntax there is only one other option I am aware of which would be to use CHR(34) & Me.SearchField.Value & CHR(34) :rolleyes:

Or you could wrap it in a user defined function something like:
Code:
Public Function TextWrap(ByVal StringIn as String) AS String

    TextWrap = CHR(34) & StringIn & CHR(34)

End Function

Then use it like

Code:
Me.Form.RecordsetClone.FindFirst "PN LIKE " & TextWrap(Me.SearchField.Value)
:D
 

Users who are viewing this thread

Back
Top Bottom