Subreports VBA

  • Thread starter Thread starter James
  • Start date Start date
J

James

How do I change the source code of a subreport using vba
when a report loads?

Many thanks

J
 
James said:
How do I change the source code of a subreport using vba
when a report loads?


Source code? Do you mean the (sub)report's RecordSource?
If so, it can be done in the (sub)report's Open event. For
subreports this can only be done the first time the
subreport's Open event is called.
 
Yes sorry source code. But how do I change the subreports
source code from the main report? What I mean is how do i
use the OnOpen event for a subreport?

Ive tried adding it just to the OnOpen section on the
report but when its opened from another report it comes
up with the error that it cant be changed when printing
has started.

So i was wondering if there was a way of doing it from
the main report such as Reports!Subreport.recordsource
= ? This however comes up with an error aswell saying I
cant assign a value.

Many thanks for your time.
 
Yes sorry source code. But how do I change the subreports
source code from the main report? What I mean is how do i
use the OnOpen event for a subreport?

Ive tried adding it just to the OnOpen section on the
report but when its opened from another report it comes
up with the error that it cant be changed when printing
has started.

So i was wondering if there was a way of doing it from
the main report such as Reports!Subreport.recordsource
= ? This however comes up with an error aswell saying I
cant assign a value.


If that would work, the syntax would be:
Subreport.REPORT.recordsource = "whatever"
but, as you've seen, the main report and subreport are
opened in sequence and the subreport is not ready at that
point. You can use a (sub)report's Open event only to set
its own record source.

To guard against trying to do it more than once in the
subreport's Open event, you can set it conditionally:

Static Initialized As Boolean
If Not Initialized Then
Me.RecordSource = "whatever"
Initialized = True
End If
 
Back
Top