Kyra Ledkins
Kyra Ledkins

Reputation: 19

Print Specified Pages of a Report

I have a report that has multiple subreports with page breaks in between each. I want to print only specified pages according to what is entered into one of the text controls (automatically filled in based on the selection from a combo box) on the main form. For example, when the ClientName control says 123, I want only pages 1 and 4 of the report to print.

I have tried using DoCmd.PrintOut acPages, but this was not the solution I was looking for as it print out pages 1-4 and not just 1 and 4.

I'm thinking that acPrintRange might be something else to try, but I am pretty new to Access and I'm not quite sure how to use this piece of code. I think that in order to use it the way I want I am going to have to use it in combination with If...Then...Else.

An example of how this would be done or a template of what the code would look like would be greatly appreciated!

To be clear, I am trying to code this into the OnClick event of a command button for several different page pairings.

Upvotes: 0

Views: 1301

Answers (1)

Andre
Andre

Reputation: 27634

For non-contiguous ranges, you'll have to call DoCmd.PrintOut multiple times, once per range.

E.g. to print pages 1 and 4-5:

DoCmd.PrintOut PrintRange:=acPages, PageFrom:=1, PageTo:=1
DoCmd.PrintOut PrintRange:=acPages, PageFrom:=4, PageTo:=5

Note: using names parameters like above helps to make your code self-explanatory.

Upvotes: 1

Related Questions