Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Go to a last page report

Status
Not open for further replies.

Finedean

MIS
May 4, 2006
80
US
Hi,

I used the following code to make a report go to the last page when it opens:

Private Sub Report_Open(Cancel As Integer)
Dim I As Integer
DoCmd.OpenReport "rptEndOfDayReport", acViewPreview
I = Reports!rptEndOfDayReport.Pages
SendKeys "{F5}{Delete}"
SendKeys I & "{ENTER}"
End Sub

but I am getting this error message:

The page number you entered is invalid
for example, it may be a negative or invalid range, such as 6 to 3

Does anyone knows what's the problem and how to fix it?

Thanks in advance.

dean
 
My first guess is that SendKeys could be your culprit. It is very buggy. There is an API call that Dev Ashish has put together (MS MVP) that may work a little better, and you can find it by searching Google for "MySendKeys" and if that doesn't narrow it down enough, add VBA into the search query.

Another possibility would be this: have you considered setting 'I' like this?
Code:
Private Sub Report_Open(Cancel As Integer)
Dim I As Integer
DoCmd.OpenReport "rptEndOfDayReport", acViewPreview
[BLUE]I = Reports!rptEndOfDayReport.Pages[B] - 1[/B][/BLUE]
SendKeys "{F5}{Delete}"
SendKeys I & "{ENTER}"
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top