Report Events a mystery

D

DocBrown

I'm trying to use the same subreport in a GroupHeader and Report Footer but
have it formatted slightly differently, Highlight fields, headers, etc. Is
there a way to tell when a subreport is being formatted in the
GroupHeader,GroupFooter or ReportFooter, or other sections of a report?

I thought of using the report events, but I added debug.print statements to
see the order of the events and it is making no sense. For example the
subreport in the ReportFooter gets an open before the ReportFooter On format
event. And the subreport receives an open event multiple times.

Any pointers would be very welcome.
 
A

Allen Browne

One (not very elegant) way might be to add an unbound text box to the
report. Then in the Format event of each section, set it to the value of the
section being processed: 0 = acDetail, 5 = acGroupLevel1Header, etc. To see
the numbers, open the Object Browser (F2 in code window) and see the members
of acSection.

In the subreport, you can then examine the value of the list box on the
parent report, e.g.:
=[Report].[Parent]![Text99]
and you should know what section the subreport was called from.

That's untested: let us know how you go.
 
D

DocBrown

Thanks for the suggestion. I added code in the OnFormat procedures for
ReportHeader, GroupHeader0, and ReportFooter to assign a value to a Text Box
in the report header section. I'm finding that the subreports are being
opened and formatted before the OnFormat events for the section is executed.

I had the idea of setting a global variable at these same OnFormat points
and checking that, but the results are the same. The subreport is being
processed before the section it is in.

And to top it off, the report Header OnFormat event happens again at the
very end of the report processing.

Just in case there's interest, when there is one group section displayed,
here's the order of the report opens, and reportheader, groupheader,
groupfooter, and reportfooter events:
-------------------------
Report_Open: Programs Activities Cumulative
Report_open: ZipDataGrandTotal
Report_open: ZipDataGrandTotal
ReportHeader_format: Programs Activities Cumulative
GroupHeader0_Format: Visual Arts
Report_open: ZipDataGrandTotal
GroupFooter1_Format: Visual Arts
Report_open: ZipDataGrandTotal
ReportFooter_format: Programs Activities Cumulative
ReportHeader_format: Programs Activities Cumulative
GroupHeader0_Format: Visual Arts
Report_open: ZipDataGrandTotal
GroupFooter1_Format: Visual Arts
---------------------
It's more of the same if there are multiple group sections. I sure can't see
any logic here..... Unless there's another brilliant idea, I guess I'm stuck
using a seperate subreport for the report footer.


Allen Browne said:
One (not very elegant) way might be to add an unbound text box to the
report. Then in the Format event of each section, set it to the value of the
section being processed: 0 = acDetail, 5 = acGroupLevel1Header, etc. To see
the numbers, open the Object Browser (F2 in code window) and see the members
of acSection.

In the subreport, you can then examine the value of the list box on the
parent report, e.g.:
=[Report].[Parent]![Text99]
and you should know what section the subreport was called from.

That's untested: let us know how you go.

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

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

DocBrown said:
I'm trying to use the same subreport in a GroupHeader and Report Footer
but
have it formatted slightly differently, Highlight fields, headers, etc. Is
there a way to tell when a subreport is being formatted in the
GroupHeader,GroupFooter or ReportFooter, or other sections of a report?

I thought of using the report events, but I added debug.print statements
to
see the order of the events and it is making no sense. For example the
subreport in the ReportFooter gets an open before the ReportFooter On
format
event. And the subreport receives an open event multiple times.

Any pointers would be very welcome.
 
D

DocBrown

Well, Well. I think I've figured out a way. Very obscure but it seems to work.

Bottom line is that when the same subreport is included in that group header
and then the Report Footer, Access opens the subreport as a completely
seperate object. So, I needed to figure a way for the subreport to know what
instance it is. I found this out by incrementing a static variable in the
routine every time it was opened. In the debug immediate window via a
debug.print statement I was seeing two independent sequences of counts. By
incrementing a global var the subreport could see it was not the first
instance.

The code is:
-----------------
Private Sub Report_Open(Cancel As Integer)
Static intStart As Long

'Has this instance been called yet.
If intStart = 0 Then

'Check Global var to see if the Group subreport has been called.
' If so, then this is the second instance of this subreport.
If intFooter > 0 Then
intStart = 2
Else
intStart = 1
End If

' Increment global to indicate this routine has been called.
intFooter = 1

' If this is the second instance build a different query.
If intStart = 2 Then
strWhere = "WHERE "
Else
strWhere = "WHERE ((Events.ProgramArea) in ([Reports]![Programs
Activities Cumulative]![ProgramArea_Box])) AND "
End If

[SNIP] ' build full query string here

Me.RecordSource = strQuery
End If
End Sub

The intStart insures the query is only built and assigned on the first open.
 
A

Allen Browne

Okay, if we're looking at obscure possiblities, here's another.

Add a text box to bound to:
=[Sub1].[Report].[hWnd]
using your subreport name instead of Sub1.

Then in the subreport's events test if Me.hWnd doesn't match the text box on
the parent. If it doesn't, you're in the footer:
If Me.hWnd <> Me.Parent.Text0 Then
Debug.Print "footer"
End If

That's actually taking advantage of the timing problem.

I would not like to guarantee that will work in future versions of Access
though. :)

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

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

DocBrown said:
Well, Well. I think I've figured out a way. Very obscure but it seems to
work.

Bottom line is that when the same subreport is included in that group
header
and then the Report Footer, Access opens the subreport as a completely
seperate object. So, I needed to figure a way for the subreport to know
what
instance it is. I found this out by incrementing a static variable in the
routine every time it was opened. In the debug immediate window via a
debug.print statement I was seeing two independent sequences of counts. By
incrementing a global var the subreport could see it was not the first
instance.

The code is:
-----------------
Private Sub Report_Open(Cancel As Integer)
Static intStart As Long

'Has this instance been called yet.
If intStart = 0 Then

'Check Global var to see if the Group subreport has been called.
' If so, then this is the second instance of this subreport.
If intFooter > 0 Then
intStart = 2
Else
intStart = 1
End If

' Increment global to indicate this routine has been called.
intFooter = 1

' If this is the second instance build a different query.
If intStart = 2 Then
strWhere = "WHERE "
Else
strWhere = "WHERE ((Events.ProgramArea) in ([Reports]![Programs
Activities Cumulative]![ProgramArea_Box])) AND "
End If

[SNIP] ' build full query string here

Me.RecordSource = strQuery
End If
End Sub

The intStart insures the query is only built and assigned on the first
open.

Allen Browne said:
Foiled by the timing of the events, eh? Darn.
Not sure what else to suggest.
 

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