DoCmd.RunSQL

securityman

New member
Local time
Today, 15:34
Joined
Nov 8, 2003
Messages
6
Hello All,

I have a form (frmSearch) with one textbox on it from which I would like to do a search with that one criteria.

I have a FIND button from which I would click and it would Search for the above criteria.

In the OnClick event of the button I am trying to use DoCmd RunSQL. I have set up a variable (SQL) as a string and have placed in that variable an SQL statement. (see below)

I have placed this variable as the argument of the DoCmd (DoCmd RunSQL SQL) but I get an error. The Error says, "The RunSQL action requires an argument consisting of an SQL statement".

I looked in HELP and this is the exact way it was done there (unless I am mistaken).

Could any one tell me what I am doing wrong.


Dim SQL As String

SQL = "SELECT * FROM tblEMPLOYEE " & _
"WHERE tblEMPLOYEE.EmployeeID= '" & [Forms]![frmSearch]!Text1.Value
& "'" & _ (this should be on the line above)
" OR tblEMPLOYEE.LastName = '" & [Forms]![frmSearch]!Text1.Value & "'" & _
" OR tblEMPLOYEE.Pass = '" & [Forms]![frmSearch]!Text1.Value & "'" & _
" OR tblEMPLOYEE.LP1 = '" & [Forms]![frmSearch]!Text1.Value & "'" & _
" OR tblEMPLOYEE.LP2 = '" & [Forms]![frmSearch]!Text1.Value & "'" & _
" OR tblEMPLOYEE.LP3 = '" & [Forms]![frmSearch]!Text1.Value & "'" & _
" OR tblEMPLOYEE.LP4 = '" & [Forms]![frmSearch]!Text1.Value & "'" & _
" OR tblEMPLOYEE.LP5 = '" & [Forms]![frmSearch]!Text1.Value & "';"

DoCmd.RunSQL SQL


Thanks!

Securityman
 
Security,

The DoCmd.RunSQL can't do a "Select * ..."

Where would it put the things that it selects? It is used for things like
Delete or Update queries.

The "Select * ..." SQL can be used as the RecordSource of a form, the
RowSource of a combo (or listbox), or as a recordset in VBA.

Wayne
 

Users who are viewing this thread

Back
Top Bottom