Query SQL in a form

sales@scantechintl.com

Registered User.
Local time
Today, 16:08
Joined
Oct 31, 2000
Messages
24
Hello,

Can anyone tell me what the difference is in the SQL generated in a query and putting that same code in a form?

This is the SQL from the query:

SELECT Employees.ID
FROM Employees;

This is what I put in the form:

Private Sub Text1_Click()
Dim SS
SS = "SELECT Employees.ID FROM Employees;"
DoCmd.RunSQL SS
End Sub

I get a RunTime "2342" error. It says the SQL needs an argument.

I would appreciate any help or ideas on this.

Thank you.
 
The docmd.runsql action can only be used for
running Action queries or data definiton queries i.e any of the following query types

...Action Query type...
Append
Delete
Make-table
Update

..Data-definition queries..
Create a table
Alter a table
Delete a table
Create an index
Delete an index

If you look at your code all it is trying to do is say

Select some records from the Employees.id
end of story

Access has no way of knowing what you want to do with the records selected

If you want to assign the SQL string as a recordsource to a form or report then simple
assign the SQL string to the forms recordsource e.g
me.recordsource = SS
me.requery

Tip:
It is a good idea to explictly dim the Sql variable as a String type rather than use the default Variant

hope this helps
Regards
Trevor from www.accesswatch.co.uk
 
Trevor,
Thank you very much for replying to my question. I wonder, is this so basic that all Access progammers would know it? No need to answer.

At any rate, I printed out your textbook answer and stapled it in my access user guide manual.

Thanks again.
John Tamaro
 

Users who are viewing this thread

Back
Top Bottom