×
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: error in null values

wildcard search: error in null values

wildcard search: error in null values

(OP)
I have a form that uses a wildcard search, the results of the search are places in a subform. But when Input a word into the search that isn't in the table, the search comes up blank. Heres the code

CODE

Private Sub refresh_Click()
Dim x As String

If IsNull(Me.find) Then
MsgBox "Please enter search criteria.", , "Natural Catalog"
Me.find.SetFocus
Exit Sub
End If
x = "SELECT * FROM Program_Name WHERE Program_Name.Description LIKE "
x = findLibSQL + "'*" + Me.find + "*'"

Me.RecordSource = findLibSQL

If IsNull(x) = True Then
MsgBox "No records matching the criteria", vbExclamation, " Database -Library Search'"
Me.find.SetFocus

End If

End Sub
Please help me with the error, thank you

RE: wildcard search: error in null values

You've set x to be a string:
x = "SELECT * FROM Program_Name WHERE Program_Name.Description LIKE "
x = findLibSQL + "'*" + Me.find + "*'"
You then test to see if it's NULL? - it won't be!

You haven't specified what program you're using, but the usual way of doing this would be to construct your query (using the concatenation operator '&' rather than the addition operator '+'), then open a recordset (using conn as your db connection)

Set myRST = conn.Execute(x)
If myRST.EOF Then
MsgBox "No records matching the criteria", vbExclamation, " Database -Library Search'"
Else
Set myControl.Recordsource = myRST
End If

You should also look at using a stored procedure (if you're using a SQL database) or a parameter query (in Access) to avoid the potential dangers of a SQL injection attack, See:
http://search.microsoft.com/search/results.aspx?qu=%22SQL+injection+attack%22&View=msdn&st=b&c=4&s=1&swc=4

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

Steam Engine enthusiasts: www.essexsteam.co.uk

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