Click to See Complete Forum and Search --> : SQL Like in VB


BillyO
November 10th, 1999, 11:28 AM
I have a form that I need to add the ability to search for mult parameters in a query by the end user. I am having trouble with running an SQL query from my app with the LIKE operator
For instance:
Query from three text boxes; txtFirm , txtFirstName, txtLastName
Access database table called KDetail Using ADO control w/ Access 2000
---------------
Private Sub cmdSearch_Click

Dim aSQL as string '
Dim A, B, C as String
A= txtFirm
B= txtFirstName
C= txtLastName
aSQL = "SELECT * FROM KDetail WHERE Firm Like '"&(A)&"' AND FirstName Like" & _
" '"&(B)"' AND LastName Like '"&(C)"'"
If adoKDetail.Recordset.RecordCount = 0 Then
msgbox("No Record Found")
End If
End Sub
-----------------

When the code runs it doesn't allow for partial information ie Stev* for Steve
I only get the msgbox "No Record Found"

Bill

November 10th, 1999, 12:23 PM
First, speaking explicitly to make the routine 'clean' the lines:
a=txtfirm
b=txtfirstname
c=txtlastname
should be changed to:
a=txtfirm.text
b=txtfirstname.text
c=txtlastname.text
Second, as a test, search explicitly for "Stev*" as noted. It should allow it. Explicitly add the * in the SQL.

November 10th, 1999, 07:24 PM
Use %, do not use *
This is feature of ADO !!!

BillyO
November 11th, 1999, 02:56 PM
It worked well....Thanks