Form value = sql result

k_heppner

New member
Local time
Today, 00:46
Joined
Apr 19, 2000
Messages
8
Hi there

I'm trying to set a form value equal to the result of an sql query. I know the query works, when I run it alone, it returns the correct result. Basically this is how I'm doing it:

Me.OpenRep = DoCmd.RunSQL("query")

but I get the error function or variable expected at the top line of the on_load event (where this is all happening). Any help is greatly appreciated.
 
docmd.RunSQL is for SQL.
to run a query use cmd.OpenQuery.

A query is based on SQL and you can see that SQL if you go to design window of the query and click on view SQL. You can even then copy that over to your code window, and

Dim strSQLStuff as String

strSQLStuff = "[Copied stuff]"

docmd.RunSQL strSQLStuff

In this way, you do not have to save a query and noone will accidentally run it without knowing what it is or does.
 

Users who are viewing this thread

Back
Top Bottom