By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,705 Members | 1,777 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,705 IT Pros & Developers. It's quick & easy.

How to browse through report pages automatically?

100+
P: 176
Hello forum!

I've combined table of contents subreport to a report using Microsoft function:
http://support.microsoft.com/kb/210269

The table of contents table combines itself if user goes through all the pages of a report first. Is there a way to make Access to go through all the pages of the report automatically, without showing this operation, in order for the table of contents table to be generated for the user as he or she views the report?

Thanks!
Aug 6 '07 #1
Share this Question
Share on Google+
9 Replies


FishVal
Expert 2.5K+
P: 2,653
Hello forum!

I've combined table of contents subreport to a report using Microsoft function:
http://support.microsoft.com/kb/210269

The table of contents table combines itself if user goes through all the pages of a report first. Is there a way to make Access to go through all the pages of the report automatically, without showing this operation, in order for the table of contents table to be generated for the user as he or she views the report?

Thanks!
Hi, Michael.

I suppose it may be a Form with timer, where OnTimer event handler send {PGDN} key to the Report window via SendKeys function.
Aug 6 '07 #2

100+
P: 176
Hi, Michael.

I suppose it may be a Form with timer, where OnTimer event handler send {PGDN} key to the Report window via SendKeys function.
Thanks FishVal,

And how does the program will know to close the report, when getting to the last page?

Michael.
Aug 6 '07 #3

FishVal
Expert 2.5K+
P: 2,653
Thanks FishVal,

And how does the program will know to close the report, when getting to the last page?

Michael.
Report.Page property returns current page number, Report.Pages property returns total pages in a report.
Aug 7 '07 #4

100+
P: 176
Report.Page property returns current page number, Report.Pages property returns total pages in a report.
That works.
Thanks a lot.
Aug 7 '07 #5

100+
P: 176
That works.
Thanks a lot.
I'll have to get back on this:

I've tried to create a procedure that will browse the form and close it, with no avail:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Report_Open(Cancel As Integer)
  2.     Call InitToc 'procedure that creates table of contents for the report and will be shown
  3.                  'on the first page of the next openning.
  4.     Delay (5)
  5.     MsgBox Me.Pages 'returns 0
  6.     For i% = 1 To 100 ' i cant use Me.Pages or Reports!myReport!Report.Pages because they return 0, instead of 100+  - why is that?
  7.         SendKeys "{PGDN}", True 'an error pop-up box is shown and says 'The action can't be carried out when proceeding other events'
  8.                                 'also, this command is being generated BEFORE and not after the report loads all its data, which is ipropriate
  9.     Next i%
  10.     DoCmd.Close acReport, "rptVisit" 'this command doesn't executes at all
  11. End Sub
Expand|Select|Wrap|Line Numbers
  1. Sub Delay(Delay_Time As Integer)
  2.                      'Delay_Time > Sets duration.
  3.     Start = Timer    ' Set start time.
  4.     Do While Timer < Start + Delay_Time
  5.         DoEvents     ' Yield to other processes.
  6.     Loop
  7. End Sub
Aug 11 '07 #6

Scott Price
Expert 100+
P: 1,384
From M$ Help file:

Remarks
You can use the Pages properties in an expression, a macro, or Visual Basic.

This property is only available in Print Preview or when printing.

To refer to the Pages property in a macro or Visual Basic, the form or report must include a text box whose ControlSource property is set to an expression that uses Pages. For example, you can use the following expressions as the ControlSource property setting for a text box in a page footer.

This expression Prints
=Page A page number (for example, 1, 2, 3) in the page footer.
="Page " & Page & " of " & Pages "Page n of nn" (for example, Page 1 of 5, Page 2 of 5) in the page footer.
=Pages The total number pages in the form or report (for example, 5).
Also example from same source:
The following example displays a message that tells how many pages the report contains. For this example to work, the report must include a text box for which the ControlSource property is set to the expression =Pages. To test this example, paste the following code into the Page Event for the Alphabetical List of Products form.

Dim intTotalPages As Integer
Dim strMsg As String

intTotalPages = Me.Pages
strMsg = "This report contains " & intTotalPages & " pages."
MsgBox strMsg
Part of the problem is that reports are not automatically paginated like forms are... i.e. the record counter on the bottom of a form shows what record you are currently viewing as well as the total records avail... Reports may show the current page, but will not show total pages in the equivalent navigation buttons on the bottom of the print preview window. This is because the pagination of a report (especially long reports) takes plenty of time, and should only be done as necessary (which M$ says is on print, not preview).

These examples from the help file appear to work around this problem, but only by referring to a PageCount control placed somewhere on the report.

Hope this helps!

Regards,
Scott
Aug 11 '07 #7

FishVal
Expert 2.5K+
P: 2,653
I'll have to get back on this:

I've tried to create a procedure that will browse the form and close it, with no avail:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Report_Open(Cancel As Integer)
  2.     Call InitToc 'procedure that creates table of contents for the report and will be shown
  3.                  'on the first page of the next openning.
  4.     Delay (5)
  5.     MsgBox Me.Pages 'returns 0
  6.     For i% = 1 To 100 ' i cant use Me.Pages or Reports!myReport!Report.Pages because they return 0, instead of 100+  - why is that?
  7.         SendKeys "{PGDN}", True 'an error pop-up box is shown and says 'The action can't be carried out when proceeding other events'
  8.                                 'also, this command is being generated BEFORE and not after the report loads all its data, which is ipropriate
  9.     Next i%
  10.     DoCmd.Close acReport, "rptVisit" 'this command doesn't executes at all
  11. End Sub
Expand|Select|Wrap|Line Numbers
  1. Sub Delay(Delay_Time As Integer)
  2.                      'Delay_Time > Sets duration.
  3.     Start = Timer    ' Set start time.
  4.     Do While Timer < Start + Delay_Time
  5.         DoEvents     ' Yield to other processes.
  6.     Loop
  7. End Sub
Hi, Michael.

Here is tested code. Its a complete module of a form which contains one button opening report and starting autobrowsing.
Report.Pages property will return 0 until the whole report will be formatted.
So there are at least two options:
  • to wait until report will be formatted and then start browsing
  • to consider the report to be on the last page then Report.Page does not grow any more (as in the following example)
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Const Interval = 1000 '1000 ms between pages
  3.  
  4. Private Sub Command0_Click()
  5.  
  6.     Dim stDocName As String
  7.  
  8.     stDocName = "rptSampleReport"
  9.     DoCmd.OpenReport "rptSampleReport", acPreview
  10.     Me.TimerInterval = Interval
  11.     Me.OnTimer = "[Event Procedure]"
  12.  
  13. End Sub
  14.  
  15. Private Sub Form_Timer()
  16.  
  17.     Dim lngPage As Long
  18.  
  19.     On Error GoTo CancelTimer
  20.  
  21.     With Reports!rptSampleReport
  22.  
  23.         On Error GoTo ExitSub 'the next row fails if no report is in focus
  24.         If Screen.ActiveReport.Name = "rptSampleReport" Then
  25.             lngPage = .Page
  26.             SendKeys "{PGDN}", True
  27.             If .Page = lngPage Then GoTo CancelTimer
  28.         End If
  29.         On Error GoTo 0
  30.  
  31.     End With
  32.  
  33. ExitSub:
  34.     Me.TimerInterval = Interval
  35.     Exit Sub
  36.  
  37. CancelTimer:
  38.     Me.OnTimer = ""
  39.  
  40. End Sub
  41.  
Aug 11 '07 #8

100+
P: 176
Hello FishVal!

Sorry, I haven't been around for a while...

Your code works very well. A neat way to browse the pages.

thanks :]

Michael.
Sep 18 '07 #9

FishVal
Expert 2.5K+
P: 2,653
Not a problem.
You are welcome.

Best regards,
Valentine
Sep 18 '07 #10

Post your reply

Sign in to post your reply or Sign up for a free account.