Page Count In VBA

Manged

Registered User.
Local time
Today, 06:45
Joined
Jun 30, 2010
Messages
10
Is there any way to count the number of pages in a report in VBA? All i want to do is keep the user from printing the report if it is more than 1 page.
 
Last edited:
My guess is that what would cause the report to be more that one page is the number of records in the report's record source. If this is true, you could use VBA code to check the record count of the report's record source. If within the desired range of records then open the report.
 
Yes, this is true but some of the records are longer/larger than others and since it is set to allow the records to grow/wrap this method would end up being fairly inacurate. I probably should have stated that earlier but there it is now... Thx for the try though :)
Any other ideas would be appreciated.
 
Is there not some way to get the value from the text box on the report that gives the page number? OR
If there is a way to tell it to move to the next page on the open event then if it gives an error "resume next" and it's ok to open or if there isnt then close the report.
 
Last edited:
Figured it out:

Dim intTotalPages As Integer
Dim strMsg As String
intTotalPages = Me.[Pages]
strMsg = "This report contains " & intTotalPages & " pages."
If intTotalPages > 1 Then
MsgBox strMsg
End If
 
Glad you got it figured out.

Thank you for sharing your solution so other may benefit! :)
 
Where is the best place to add this

Dim intTotalPages As Integer
Dim strMsg As String
intTotalPages = Me.[Pages]
strMsg = "This report contains " & intTotalPages & " pages."
If intTotalPages > 1 Then
MsgBox strMsg
End If

at the on load or at onPage etc?
Thanks
 

Users who are viewing this thread

Back
Top Bottom