Accessing subreport HasData property

G

Guest

I have recently been contracted to maintain an Access 97 database and I am
having problems accessing the HasData property of a subReport from a VB
standard module (not the reports module).

I can access the HasData property of the main report using:
"If Reports("rptname").HasData Then"
However I can't get a reference to the subreport via the Reports collection
as Access does not recognise that it is open.

I have attempted to enumerate the Controls collection and while this has a
SourceObject property it returns a string not an object.

I have also enumerated the database Containers collection to gain a
reference to the Document object for the report however this does not expose
the RecordSource property until you open the report in design mode.

Consequently you have to open the report in design mode, obtain the
RecordSource property, close the report then use something like DCount to
determine if the underlying table for the subreport contains any data. Of
course this flashes the report in design view on the screen.

Due to the way the code has been written it would require a major rewrite to
use the "NoData" event in the report to solve the problem - the same code is
used to format and display approximately 100 reports.

Does anyone know how I can access the the subreport via the report object so
that I can get at it's "HasData" property?

Thanks in advance,

Ray
 
A

Allen Browne

Subreports are not open in their own right, i.e. they are not part of the
Reports collection.

If you have a subreport control named Sub1, then on the main report you can
refer to it with:
Sub1.Report

Example:
=IIf([Sub1].[Report].[HasData], Nz([Sub1].[Report]![txtTotal],0), 0)
 
G

Guest

Thanks Allen however I'm not attempting to access the subreport from the main
report - I'm trying to access the subreport from code running in a standard
module.

Cheers,

Allen Browne said:
Subreports are not open in their own right, i.e. they are not part of the
Reports collection.

If you have a subreport control named Sub1, then on the main report you can
refer to it with:
Sub1.Report

Example:
=IIf([Sub1].[Report].[HasData], Nz([Sub1].[Report]![txtTotal],0), 0)

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Ray said:
I have recently been contracted to maintain an Access 97 database and I am
having problems accessing the HasData property of a subReport from a VB
standard module (not the reports module).

I can access the HasData property of the main report using:
"If Reports("rptname").HasData Then"
However I can't get a reference to the subreport via the Reports
collection
as Access does not recognise that it is open.

I have attempted to enumerate the Controls collection and while this has a
SourceObject property it returns a string not an object.

I have also enumerated the database Containers collection to gain a
reference to the Document object for the report however this does not
expose
the RecordSource property until you open the report in design mode.

Consequently you have to open the report in design mode, obtain the
RecordSource property, close the report then use something like DCount to
determine if the underlying table for the subreport contains any data. Of
course this flashes the report in design view on the screen.

Due to the way the code has been written it would require a major rewrite
to
use the "NoData" event in the report to solve the problem - the same code
is
used to format and display approximately 100 reports.

Does anyone know how I can access the the subreport via the report object
so
that I can get at it's "HasData" property?

Thanks in advance,

Ray
 
A

Allen Browne

So are you calling the generic function in one of the events of the subform
itself? If so, pass a reference to the report in your event procedure like
this:
Call MyFunction(Me)
assuming that MyFunction is delcared like this:
Public Function MyFunction(rpt As Report)
If you have the function name directly in the On Format property of the
section, use:
=MyFunction([Report])
without changing the name.

If you are not using the report events like that, I doubt you will get this
to work. Reports are not like forms. They use a forward scrolling recordset
only, and the subreport can have multiple instances on the report, possibly
even occurring for every record. It is therefore meaningless to talk about a
"subreport" after the events have run and the report has been laid out.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Ray said:
Thanks Allen however I'm not attempting to access the subreport from the
main
report - I'm trying to access the subreport from code running in a
standard
module.

Cheers,

Allen Browne said:
Subreports are not open in their own right, i.e. they are not part of the
Reports collection.

If you have a subreport control named Sub1, then on the main report you
can
refer to it with:
Sub1.Report

Example:
=IIf([Sub1].[Report].[HasData], Nz([Sub1].[Report]![txtTotal],0), 0)

Ray said:
I have recently been contracted to maintain an Access 97 database and I
am
having problems accessing the HasData property of a subReport from a VB
standard module (not the reports module).

I can access the HasData property of the main report using:
"If Reports("rptname").HasData Then"
However I can't get a reference to the subreport via the Reports
collection
as Access does not recognise that it is open.

I have attempted to enumerate the Controls collection and while this
has a
SourceObject property it returns a string not an object.

I have also enumerated the database Containers collection to gain a
reference to the Document object for the report however this does not
expose
the RecordSource property until you open the report in design mode.

Consequently you have to open the report in design mode, obtain the
RecordSource property, close the report then use something like DCount
to
determine if the underlying table for the subreport contains any data.
Of
course this flashes the report in design view on the screen.

Due to the way the code has been written it would require a major
rewrite
to
use the "NoData" event in the report to solve the problem - the same
code
is
used to format and display approximately 100 reports.

Does anyone know how I can access the the subreport via the report
object
so
that I can get at it's "HasData" property?
 

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