Retrieving query result in code

  • Thread starter Thread starter Robert
  • Start date Start date
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
 
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)
 
Thank you very much.
Rick Brandt said:
SomeVariable = DCount("*", "QueryName")

or

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