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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print page ? to page ? 1

Status
Not open for further replies.

firebolt

Instructor
Aug 4, 2001
27
0
0
CA
Hi, I have a report that has 150 pages. I would like to tell the printer to print the first 25 pages, perhaps the next 15 and then 20 or 15 for example. How do I accomplish this task using reports, macros or VBA?

Thanks,
Firebolt
 
You could try using the PrintOut function...

DoCmd.PrintOut [printrange][, pagefrom, pageto][, printquality][, copies][, collatecopies]

eg.

'Open report3 in preview
DoCmd.OpenReport "Report3", acViewPreview

'print pages 1 to 4 in draft
DoCmd.PrintOut acPages, 1, 4, acDraft, 1, False

'close report3
DoCmd.Close acReport, "Report3"



There are two ways to write error-free programs; only the third one works.
 
Thanks GHolden; I should be more specific. When I choose a button to print a specific report (which i use a preview to check) I would like to receive a prompt that asks me to select the pages to print, similar to the one found when I choose print from the menubar and I change the properties. Being able to chunk up the report or be selective as to the pages I want is key. Itis not always necessary to print the whole report and each printing may require diff pages. Any other suggestions since printout assumes I will know the pages required ahead of time which is not always the case.

Thanks,
Firebolt
 
Hi,

You can do this by passing the values of Start page and End page as variables to a print sub.

For example...

Public Sub gPrintRange(ByVal vintStart As Integer, ByVal vintEnd as Integer,ByVal vstrReport)

'Open in preview
DoCmd.OpenReport vstrReport, acViewPreview

'print pages
DoCmd.PrintOut acPages, vintStart , vintEnd , acDraft, 1, False

'close
DoCmd.Close acReport, vstrReport

End Sub


If you then had two text boxes on a form (say txtStartPage and txtEndPage) and a button to print (cmdPrint), and possibly a text box for report name (txtReport)

in the click event of the command button you could have...

gPrintRange txtStartPage,txtEndPage,txtReport

You would want to add an error handler and some validation to the print sub (eg. make sure end page is greater than or equal to start page...)

Hope this is more what you're looking for...?





There are two ways to write error-free programs; only the third one works.
 
Excellent G. Holden this should do the trick.

Thanks,
Firebolt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top