Automatically cycle thru pages in preview

R

rbm

I want to be able to open a report in Preview Mode and then have it
automatically cycle through the pages of the report. The purpose is to
project the report on a screen and have it display page after page and, when
it reaches the end, start all over. I have been able to get this to work to
some extent using "SendKeys and "Sleep" commands. The Sleep command was done
by putting the following in a general module:

Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Basically, I have a button on a form with an OnClick procedure that does the
following:

1. Opens the report in preview.
2. Looks at the [Pages] field on the report to see how many pages there are.
3. Starts a "For . . . Next" loop with i = 1 to the number of pages in the
report.
4. In the loop, I start with a DoEvents command followed by a "Sleep 5000"
command (causes a 5 second hesitation) and then a "SendKeys "{Right}""
command that acts the same way as hitting the right arrow with the report in
preview mode.
5. When the loop ends, I have it return to the beginning and start over.

As primitive as this is, it works - but there are a lot of pitfalls. I
can't find a way to stop the looping. I can hit "Ctrl-Brk" and stop the
code, but then I have to close the Class Module screen and then close the
report. The menu bar does work during the looping so there is nothing for me
to click on to stop the process.

Also, I don't know if this will work in a runtime environment.

I would be very appreciative of any suggestions on how to handle this with
or without SendKeys. Thanks in advance.

The actual event procedure is pasted below.

Private Sub btnDisplayReport_Click()
On Error GoTo ERR_Display

Dim X As Integer
Dim N As Single
Dim strReport As String
Dim i As Integer

strReport = "rptLineChart"

N = 5 ' 5 second dely before going to next page

START_CYCLE:

DoCmd.OpenReport strReport, acViewPreview
DoCmd.RunCommand acCmdFitToWindow ' resize report to fit on the screen

X = Reports!rptLineChart!Z ' [Z] is the "Pages" field on the report
For i = 1 To X
DoEvents
Sleep N * 1000
SendKeys "{right}"
Next i
DoEvents
DoCmd.Close acReport, strReport

GoTo START_CYCLE

EXIT_Display:
Exit Sub

ERR_Display:
DoCmd.Close acReport, strReport
Resume EXIT_Display
 
C

Chuck

I want to be able to open a report in Preview Mode and then have it
automatically cycle through the pages of the report. The purpose is to
project the report on a screen and have it display page after page and, when
it reaches the end, start all over. I have been able to get this to work to
some extent using "SendKeys and "Sleep" commands. The Sleep command was done
by putting the following in a general module:

Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Basically, I have a button on a form with an OnClick procedure that does the
following:

1. Opens the report in preview.
2. Looks at the [Pages] field on the report to see how many pages there are.
3. Starts a "For . . . Next" loop with i = 1 to the number of pages in the
report.
4. In the loop, I start with a DoEvents command followed by a "Sleep 5000"
command (causes a 5 second hesitation) and then a "SendKeys "{Right}""
command that acts the same way as hitting the right arrow with the report in
preview mode.
5. When the loop ends, I have it return to the beginning and start over.

As primitive as this is, it works - but there are a lot of pitfalls. I
can't find a way to stop the looping. I can hit "Ctrl-Brk" and stop the
code, but then I have to close the Class Module screen and then close the
report. The menu bar does work during the looping so there is nothing for me
to click on to stop the process.

Also, I don't know if this will work in a runtime environment.

I would be very appreciative of any suggestions on how to handle this with
or without SendKeys. Thanks in advance.

The actual event procedure is pasted below.

Private Sub btnDisplayReport_Click()
On Error GoTo ERR_Display

Dim X As Integer
Dim N As Single
Dim strReport As String
Dim i As Integer

strReport = "rptLineChart"

N = 5 ' 5 second dely before going to next page

START_CYCLE:

DoCmd.OpenReport strReport, acViewPreview
DoCmd.RunCommand acCmdFitToWindow ' resize report to fit on the screen

X = Reports!rptLineChart!Z ' [Z] is the "Pages" field on the report
For i = 1 To X
DoEvents
Sleep N * 1000
SendKeys "{right}"
Next i
DoEvents
DoCmd.Close acReport, strReport

GoTo START_CYCLE

EXIT_Display:
Exit Sub

ERR_Display:
DoCmd.Close acReport, strReport
Resume EXIT_Display

Insert some *break out* code before the line: next i.
The *logic* of the *break out* code:
iif keypress = chr( your choice ) then
Exit Sub (Note Exit, not End)

Can stop *show* at any time.

Chuck
 

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