PDA

Click to See Complete Forum and Search --> : SQL Using LIKE


RPKessler
Jul 24th, 1999, 04:12 AM
I just want to allow users to find a record based on what they type into a text box on my search form. The data control is on my main form. All attempts to use different combinations of code fail. I am out of Advil & patience!!! Please look at this code and advise.

RK


Private Sub cmdOK_Click()

If Trim(txtFind) = "" Then Exit Sub

Dim SQL As String
Dim Name2Find As String

Name2Find = Trim(txtFind.Text)

SQL = "SELECT From Customers WHERE LastName Like '%" & txtFind.Text & "%'"

With frmMain.Data1
.RecordSource = SQL
.Refresh
End With

Unload Me

End Sub

Serge
Jul 25th, 1999, 03:13 PM
What Database are you using? Access, SQL Server, Oracle???

Also, what data control are you using? Is it regular data control or ADO data control??

If you use Oracle or SQL Server then your SQL statement should be:


SQL = "SELECT From Customers WHERE LastName Like " & txtFind.Text & "%"


If you use Access database and a regular Data control then your SQL statement should be:

SQL = "SELECT From Customers WHERE LastName Like " & txtFind.Text & "*"


Regards,

------------------

Serge

Software Developer
Serge_Dymkov@vertexinc.com
Access8484@aol.com

preeti
Jul 25th, 1999, 05:40 PM
Hi,

Actually, if you are using an Oracle database then your string needs to be surrounded by single quotes, but you also need to specify WHAT you want to select:

SQL = "SELECT * From Customers WHERE LastName Like '%" & txtFind.Text & "%'"

HTH,

Preeti