The report name 'a1' you entered is misspelled or refers to a report that isn't open

aman

Registered User.
Local time
Today, 13:47
Joined
Oct 16, 2008
Messages
1,251
Hi guys

I am trying to find out the total number of pages in a report but its giving me the above error message.

Code:
Dim MyPageNum As Integer
Dim stDocName As String
i = Reports("a1").Pages

For MyPageNum = 1 To i

DoCmd.SelectObject acReport, "Students Information Report", True
DoCmd.PrintOut acPages, MyPageNum, MyPageNum
DoCmd.SelectObject acReport, "a1", True
DoCmd.PrintOut acPages, MyPageNum, MyPageNum
Next MyPageNum

Can anyone please figure it out.

Regards
AMan
 
If the report isn't open I think you'll have to access it through the reports collection with something like:

Application.CurrentProject.AllReports ("MyReportName").MyProperty

But I'm not sure .Pages is one of the properties. Where did you get that bit of info?
 
What you really need to do it run some tests and see if you can guestimate howmany records appear on one page of the report. Then divide the number of records inthe recordset/underlying query/table by this amount. This should give you the approx number of pages. Add 1 to it to be certain

Use this in your for page = 1 to pages


Next test run the code until it errors on the pages value. See what err.number appears and use this in your error trapping to exit the sub.

David
 
Hi Dcrake

When I changed my code as you suggested,it gives me an error "you entered an expression that has an invalid reference to the property pages."

Code:
Private Sub Command2_Click()
On Error GoTo Err_Command2_Click
Dim MyPageNum As Integer
Dim stDocName As String
For MyPageNum = 1 To Pages
DoCmd.SelectObject acReport, "Students Information Report", True
DoCmd.PrintOut acPages, MyPageNum, MyPageNum
DoCmd.SelectObject acReport, "a1", True
DoCmd.PrintOut acPages, MyPageNum, MyPageNum
Next MyPageNum
Exit_Command2_Click:
    Exit Sub
Err_Command2_Click:
    MsgBox Err.Description
    Resume Exit_Command2_Click
    
End Sub

Thanks
Aman
 
What value di you have for Pages? This is only a variable name. You could even try

For MyPageNum = 1 to 1000000 to test it. What you are looking for is the error number that is raised when you try to tell it to print a page that does not exist.
Then when you know that you can trap it with an exit sub

David
 
DCrake,

Please see the following code .In this the loop runs 10 times. Now in my case the number of pages to be printed are 4.The following code prints only 4 pages but it runs the loop for 10 times as I get the message 'Now Printing......'. It doesn't display any error message.

Code:
On Error GoTo Err_Command2_Click
Dim MyPageNum As Integer
Dim stDocName As String
For MyPageNum = 1 To 10
DoCmd.SelectObject acReport, "Students Information Report", True
DoCmd.PrintOut acPages, MyPageNum, MyPageNum
DoCmd.SelectObject acReport, "a1", True
DoCmd.PrintOut acPages, MyPageNum, MyPageNum
Next MyPageNum
Exit_Command2_Click:
    Exit Sub
Err_Command2_Click:
    MsgBox Err.Description

Can you please tell me how to exit loop when it tries to print a page that doesn't exist .so I don't want it to run for 10 times but just for 4 times.

Thanks
Aman
 
.pages is surely a property of a report

the standard footer on a report shows this

="Page " & [Page] & " of " & [Pages]
 
Hi Gemma-the husky

Can you please tell me exactly how to find the number of pages in a report and how to print two copies of each page.

Thanks
Aman
 
access actually process a report twice - once to set the layout etc, and count the pages, and the second time to actually print it - so you cant tell how many pages there until it has completed the first process.

eg this code in the report header print event will show you the number of pages in the report. If you try this in the reportopen event you just get 0 for the pagecount

Private Sub ReportHeader_Print(Cancel As Integer, PrintCount As Integer)
MsgBox (Me.Pages)
End Sub

-------
I think the only way to print 2 copies is to print the report twice

docmd,openreport myreport
docmd,openreport myreport

or more generically

for x= 1 to no_of_copies
docmd,openreport myreport
next
 
Hi gemma-the husky

I think you haven't seen my earlier posts.I know we can print the report twice by writing the statement twice but it doesn't collate the same pages together while printing. What I want is the same pages should print one after the another. Its not like if the report contains 10 pages then first those 10 pages will be printed out and then again the same 10 pages will be printed off.
Its like
page1 page1 page2 page2 page3 page3......page10 page10

I hope you understand my problem

Thanks
Aman
 
i dont think you can request multiple copies at runtime, with normal means

you may be able to do something with the printer object in design mode, but i am not sure
 

Users who are viewing this thread

Back
Top Bottom