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

Macro Or Code to print last page of report

Status
Not open for further replies.

jtakarsh

Programmer
Jul 15, 2003
3
0
0
US
I have report that I need to develop a macro/script to print the last page of the report. This report is used during an auction to print the list of buyers and bid numbers for the auctioneer to reference. Throughout the auction, buyers will continue to register and periodically this report will need to be reprinted.

The report is ordered by bid number, therefore newly registered buyers appear on the last page. Rather than printing the entire report, I would like to develop a script/macro to associate with a button on a form to qucikly print the last page of this report.

Is there a way to do this.

 
A quick & dirty way would be to change your report's recordsource to sort on bid numbers descending, then use the PrintOut method to print page 1 which would be the most "recent" records...



A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.
Douglas Adams
 
I thought about that except there are 2 problems with that approach. (1) I don't want to confuse the auctioneer who normally would see the report with bid numbers listed 1-100 rather than 100-1. (2) By doing this, the last record on the bottom of page one would be force to the top of page 2 when when new buyers are registered. The auctioneer just replaces the last page, in this case he would replace the first page, but the last few records that were forced to page 2 would be missing from his report since you only printed page 1 and not 1 and 2.

I hope that makes sense. In this specific case, I think I will need code to determine what the last page is and then print that last page.

Thanks for the idea. It was one that I explored before posting this question. Now if there was a way to print the pages in reverse order but retain the current sort order then I could just print page 1. Don't know if this is possible.

 
Like I said, it was quick & dirty.

I agree with your first point about the reverse order being confusing. But, point 2 could occur at any time; maybe the last page might only contain 1 record after the page break...

In any event, try code like this in the OnClick event of your command button:
Code:
Dim intPages as Integer

DoCmd.OpenReport "YourReportName", acViewPreview
intPages = Reports!YourReportName.Pages
DoCmd.PrintOut acPages, intPages, intPages
The intPages variable will contain the last page number. So, to print the last two pages, you should be able to do this:
Code:
DoCmd.PrintOut acPages, intPages - 1, intPages
Let me know if this helps......



A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.
Douglas Adams
 
Thanks that works. I thought there was a way to check for the number of pages.
 
Can this be used in Access 2000? I am getting a runtime error 2206. The page number you entered is invalid. When I step thru the code, intPages gets a zero assigned to it, which explains the error, but my report opens and has many pages, so, I don't know why it is assigning a zero. Any ideas?

Melissa
Designing Access databases since 1999
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top