Run report/query from vba ?

  • Thread starter Thread starter TonyB
  • Start date Start date
T

TonyB

Hi,
I'm working on a form. On this form I open a report,which is based upon a
query which reads criteria from the form. What I want to do before I open
the report, is to find out if that query would return any records so that
the report doesn't display blank pages. So I'm looking for a way to
programatically run the query from my form vba code, and see if it returns
any data before I open the report ? Is this possible ?
Thanks
Tony
 
Use the DCount function in the VBA.
If DCount("[FieldName]","QueryName") > 0 then
'Open Report
End if
The FieldName is on of the fields within the query, and
this would only open the report where the number of
records returned by the query is 1 or more.
 
Hi ACG,
Thanks, that worked a treat.
Tony

ACG said:
Use the DCount function in the VBA.
If DCount("[FieldName]","QueryName") > 0 then
'Open Report
End if
The FieldName is on of the fields within the query, and
this would only open the report where the number of
records returned by the query is 1 or more.

-----Original Message-----
Hi,
I'm working on a form. On this form I open a report,which is based upon a
query which reads criteria from the form. What I want to do before I open
the report, is to find out if that query would return any records so that
the report doesn't display blank pages. So I'm looking for a way to
programatically run the query from my form vba code, and see if it returns
any data before I open the report ? Is this possible ?
Thanks
Tony


.
 
Tony,

Alternatively, you could use the On No Data property of the report
itself to run this line of code:

Cancel = True

HTH,
Nikos
Hi ACG,
Thanks, that worked a treat.
Tony

Use the DCount function in the VBA.
If DCount("[FieldName]","QueryName") > 0 then
'Open Report
End if
The FieldName is on of the fields within the query, and
this would only open the report where the number of
records returned by the query is 1 or more.


-----Original Message-----
Hi,
I'm working on a form. On this form I open a

report,which is based upon a
query which reads criteria from the form. What I want to

do before I open
the report, is to find out if that query would return

any records so that
the report doesn't display blank pages. So I'm looking

for a way to
programatically run the query from my form vba code, and

see if it returns
any data before I open the report ? Is this possible ?
Thanks
Tony


.
 
Back
Top