-
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
-
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
[email protected]
[email protected]
-
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