Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

wildcard search using visual basic 1

Status
Not open for further replies.

poppadoc75

Computer
Jul 22, 2005
10
In Access, I have a form that uses a wildcard search but i can't seem to make it work.
Heres the code
Code:
Private Sub SEARCH_Click()
Dim findLibSQL As String

If IsNull(Me.SEARCH_DES) Then
MsgBox "Please enter search criteria.", , "Natural Catalog"
Me.SEARCH_DES.SetFocus
Exit Sub
End If
findLibSQL = "SELECT * FROM [PROGRAM_NAME]![Descritption] WHERE [SEARCH_DES] LIKE "
findLibSQL = findLibSQL + "*" + Me.SEARCH_DES + "*"

Me.RecordSource = findLibSQL
If Me.SEARCH_DES = "" Then
MsgBox "No records matching the criteria", vbExclamation, " Database -Library Search'"

End If

End Sub
I get a syntax at Me.Recordsource = findLibSQL
Thank you in Advance
 
Replies continue below

Recommended for you

Try
findLibSQL = findLibSQL + "'*" + Me.SEARCH_DES + "*'"
Francis
 
Depends on the database back end that you're using. Most of the standard SQLs use % as the multicharacter wildcard. The * is really a MS Access thing. Also the string concatenation operator is & NOT +

Good Luck
johnwm
________________________________________________________
To get the best from these forums read faq731-376 before posting

Steam Engine enthusiasts:
 
I tried findLibSQL = findLibSQL + "'*" + Me.SEARCH_DES + "*'", then I got a Syntax error in FROM Clause.
 
I got the search to work now, but now when I input a value that isn't in the table, the screen goes blank. Here's the code as it is now.
Private Sub SEARCH_Click()
Dim findLibSQL As String
Code:
If IsNull(Me.SEARCH_DES) Then
MsgBox "Please enter search criteria.", , "Natural Catalog"
Me.SEARCH_DES.SetFocus
Exit Sub
End If
findLibSQL = "SELECT * FROM Program_Name WHERE Program_Name.Description LIKE "
findLibSQL = findLibSQL + "'*" + Me.SEARCH_DES + "*'"

Me.RecordSource = findLibSQL
If me.search_des = "" Then
MsgBox "No records matching the criteria", vbExclamation, " Database -Library Search'"

End If

End Sub
Thank you
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor