Link to home
Create AccountLog in
Avatar of kabradley
kabradley

asked on

Global Variable for SubReport Page Number - Gives Ending Page Not Beginning

Afternoon Experts!

I have a report that acts as a capsule for several subreports. Each subreport has its own header/footer. I also have a global integer variable for each of the sub reports. Essentially what I am in the process of doing is making a table of contents for the capsule report that shows the first page number for each of the subreports.

On each of the report header/footers I have:
If me.report.blah.reports.hasdata then
globalVariable = Me.page
End If

This code works great, except that on subreports that span multiple pages, the variable is set to the last page of the subreport instead of the first.

How do I make sure that it is infact the first page number of the subreport that is shown?

Thank you!
Avatar of GRayL
GRayL
Flag of Canada image

As you are dealing with subreports, did you try:  GlobalVariable = Me!ReportName.Report.Page
--------------------------------------------------------------------------------------------^--enter actual name here.
Now that I think of it, every time you entered a header, you would reset the counter.   You want to catch just the first header page number.  Wouldn't you need a globalvariable for each header?  I think you have to re-think the process.  Something like Build a string (Static) which included the Header unique thing and add the page number.  At the end of the report you have a String that looks like"

Header 1, 3, Header 2, 6, Header 3, 8, etc.  
-------------^--------------^---------------^--page no's
Avatar of kabradley
kabradley

ASKER

Ray,

I tried your first suggestion, but that didn't seem to do it.

What I have, to explain further is 7 subreports, each in their own header or footer. I also have 7 globalvariables that were intended to house each subreports' first page. I then have a string declared in the on_Format of the parent report. This builds the table of contents text i.e.
strText = "Reports1................." & gintCHPage  <-- First Subreport & First Global Page Variable
If Report2.report.hasdata then
strtext = strText & vbcrlf & "Report2....................." & gintReport2Page

Etc,etc.

If the report is visible and has data it will be in the string and consequently the text box for the T.O.C.

Any other ideas?
ASKER CERTIFIED SOLUTION
Avatar of GRayL
GRayL
Flag of Canada image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Yup, that's most definitely a plan Ray. I was trying to do that exact thing, (which is why I asked for help) but I didn't know / understand about static variables. I read up on them and after some finagling they its working fine! Thank you, Thank you!!
Great fix to my problem!
Hey Ray, Hopefully you'll see this comment:

I was working on the report and everything was fine. I closed the report and then reopened it and upon reopening it I got a "Font Overload error" it gave me that about 4 in a row then a "critical alert" error. I closed the database rebooted and opened the database back up. Now when I try and load the report nothing happens....if i right+click to go into design mode nothing happens...

What in the world just happened?!?
Can you show me the code change you made?  When you set a static variable, it should only last as long as the module it is in is active - ie. until the report is closed.  I have no idea how you use the global to 'create' your TOC.  
The code used is as follows:

Static iFirst As Integer
iFirst = iFirst + 1
Me.GroupFooter0.Visible = Me.subrptSummary.Report.HasData
If Me.GroupFooter0.Visible Then
    If iFirst = 1 Then
        gintSumPage = Me.Page
    End If
Else
    gintSumPage = 0
End If

The reason I'm using a global is because as you can see the global is set to the page number. The global is then used in a string that is created in the on_Format of the report header. This string houses the data such as:
Report Summary................................................... (and then the page number i.e. global variable)

Onto the mysterious crashing of the report...
I can't open the report, I can't open the "Design view", I can't export the report (Access can't find it), I can't copy it and then paste it...I'm worried and confused b/c I've spent a great deal of time on this report and now can't seem to get control of it.

Any suggestion on what to do?
Well, you know what they say about backup's.  I don't suppose you have a copy of the report before you started the TOC part?  What about each of the 5 subreports - do they exists as reports which you insert into a subreport control?
The next steps are Compact and Repair, and Decompile.  Are you OK with doing those two steps?

Make a backup first,  then do the Compact and Repair.  Any difference?  

As to the decompile - Google - Access Decompile - and read several of the articles so that you have a good understanding of what is happening - again from a backup.  
Ray, ahh making me feel so dumb about the backups. Literally you have no idea how much I have to 'preach' that to fellow employees here at the office.....a bit of irony for this nice friday afternoon I suppose :)

Fortunately the subreports are separated into their own reports and what I did to the parent report is still pretty fresh in my mind, so I've already started rebuilding it.

I C&R'ed but to no avail. I'll try the decompile and see if that works.

Don't you hate it when this happens? lol
Sorry my friend but the I have been 'summoned' for pretravel packing.  2Weeks
No worries Ray. I just redid the reports and actually found a few areas where changes could be made to speed everything up. So, it all worked out in the end.

Have a safe trip!