×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

wildcard search using visual basic

wildcard search using visual basic

wildcard search using visual basic

(OP)
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

RE: wildcard search using visual basic

Try
findLibSQL = findLibSQL + "'*" + Me.SEARCH_DES + "*'"
Francis

RE: wildcard search using visual basic

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: www.essexsteam.co.uk

RE: wildcard search using visual basic

(OP)
I tried findLibSQL = findLibSQL + "'*" + Me.SEARCH_DES + "*'", then I got a Syntax error in FROM Clause.

RE: wildcard search using visual basic

(OP)
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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources