Retrieving query result in code

R

Robert

Hello.

I need to use a count of records returned by a query in my form code. I can
use an actual count of the records returned by a query or I can use the
COUNT function, either way, but I need to get the result in code not on the
form itself. If I use Docmd.Openquery or Docmd.Runsql is there some way to
have the result i.e. a record count returned in the code? Or is there some
other way?

Robert
 
R

Rick Brandt

Robert said:
Hello.

I need to use a count of records returned by a query in my form code.
I can use an actual count of the records returned by a query or I can
use the COUNT function, either way, but I need to get the result in
code not on the form itself. If I use Docmd.Openquery or
Docmd.Runsql is there some way to have the result i.e. a record count
returned in the code? Or is there some other way?

Robert

SomeVariable = DCount("*", "QueryName")

or

SomeVariable = CurrentDB.OpenRecordSet("SELECT Count(*) FROM
QueryName").Fields(0)
 
R

Robert

Thank you very much.
Rick Brandt said:
SomeVariable = DCount("*", "QueryName")

or

SomeVariable = CurrentDB.OpenRecordSet("SELECT Count(*) FROM
QueryName").Fields(0)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top