Trying to run a select statement during the execution of a report

J

J

I'm trying to run a select statement to count the number of records that
meets a specific criteria during the execution of a report. I'm using vb and
can figure out what to use to do that. I'll need to run the query and pass
the data to a field in the report. Any help is appreciated.
 
F

fredg

I'm trying to run a select statement to count the number of records that
meets a specific criteria during the execution of a report. I'm using vb and
can figure out what to use to do that. I'll need to run the query and pass
the data to a field in the report. Any help is appreciated.

You wish a count of records in the report that meet certain criteria?
Why a Select statement? Why vb?
1) First of all, you cannot run a Select statement in VBA using
RunSQL, i.e. DoCmd.RunSQL "Select blah blah blah"

2) If you have a saved query, you could read the value returned by
that query using DLookUp.
If the query returns just the one record value, use an unbound control
in the report:

=DLookUp("FieldName]","QueryName")

Better yet, since you are counting records that are in the report....
3) Just use an unbound control in the report, such as:

=Sum(IIf([SomeControl] = SomeCriteria,1,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

Top