Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What is wrong with this Query

Status
Not open for further replies.

shyamsundar

Programmer
Aug 23, 2002
75
IN
Hi all,

I am trying to run this query and pass the value into variable and print it in the report.

docmd.runsql "Select count(*) as dcnt from table1"

and I am getting the error "A RunSql action requires an argument consisting of an SQL Statement"


Please Help



Shyam
cwizshyam@yahoo.com
 
DoCmd.RunSQL is used to run an action query (append, delete, update)
Your SQL is a Select query...

You have to open a recordset based on your select statement, get the value from the field into a variable, close the recordset and do whatever you want.


Set rst = CurrentDb.OpenRecordset("Select count(*) as dcnt from table1")
varValue = rst.Fields("dcnt")
rst.Close
Set rst = Nothing

'do whatever you want with varValue

Good luck



[pipe]
Daniel Vlas
Systems Consultant

 
Dear Daniel Thanx

brilliant
Shyam
cwizshyam@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top