Only print part of a report (1 Viewer)

moose

c'mon Chelsea
Local time
Today, 06:19
Joined
May 18, 2001
Messages
139
my report can sometimes be quite long and i would like it so that when a user clicks the print icon, it only prints the 2 pages on display (TwoPagePreview) instead of the entire report.
Can anyone help please?

If you are feeling very helpful, I am still trying to get the report to open in TwoPagePreview by default.

Please help me
 

moose

c'mon Chelsea
Local time
Today, 06:19
Joined
May 18, 2001
Messages
139
is it that noone can help or have i not made my problem clear enough?
i need to get this bit finished so that i can go live with my db to prevent any more duplicate data entry

Please please please please help me
 

SforSoftware

(NL) SnelStart specialist
Local time
Today, 07:19
Joined
Aug 16, 2003
Messages
239
Moose,

For me your problem is clear enough, but I really don't know how you can do that.

But I've got a solution for the second problem: After opening the report with:
DoCmd.RunCommand acCmdPreview
you give the command:
DoCmd.RunCommand acCmdPreviewTwoPages
 
R

Rich

Guest
That's already been suggested which is why you should continue with the original thread
 

moose

c'mon Chelsea
Local time
Today, 06:19
Joined
May 18, 2001
Messages
139
I appreciate that this is pretty much the same as my last post except that i did mention that i have a macro to open a query which gives the report its data. I have entered this code into the OnOpen event of the report but just get a debug screen come up.
when i exit the debug screen it opens in TwoPagePreview, so it works ok but for the debug screen.
as for the printing, that is just another problem, no point running the report if it is going to print 30 pages when all i need is two of them.

If you could post the entire code i need to open the Query and Report it might help me.
At present the macro
1. OPENS QUERY
2. OPENS REPORT
3. CLOSES FORM
4. MAXIMISES THE REPORT

Does this help?
 

SforSoftware

(NL) SnelStart specialist
Local time
Today, 07:19
Joined
Aug 16, 2003
Messages
239
Ok, you're working in a macro.

Then take these steps:
1. OpenReport
2. RunCommand -> beneath select somthing like 'PreviewTwoPages'
3. Close Form

You actually don't have to open the query. The report does dat itself.
 

moose

c'mon Chelsea
Local time
Today, 06:19
Joined
May 18, 2001
Messages
139
Thank you very much, that done the trick, I thought it would be something simple, it's just knowing where to find the bits and bobs.

Still having no luck on the printing side of the problem though (Hint Hint)
 

Sorrells

Registered User.
Local time
Today, 06:19
Joined
Jan 13, 2001
Messages
258
Hello,

I am looking for a way in Access XP to specify which pages are to be printed in a report also. I have worked in A97 most of the time and hoped when I 'moved up' this capability would be there. Well, it is not staring me in the face! :D

I'll keep reviewing the posts for any gems. But if this resurrected post catches anyone's fancy, please feel free to dive in!
 

SforSoftware

(NL) SnelStart specialist
Local time
Today, 07:19
Joined
Aug 16, 2003
Messages
239
You can (and I think you could in 97) specify the pages to print with the command PrintOut:
Code:
DoCmd.OpenReport "MyReport", , acViewPreview
DoCmd.PrintOut...
DoCmd.Close acReport, "MyReport"
But (for moose) the problem is how to determine which pages are currently on the screen in Preview-mode.
 

SforSoftware

(NL) SnelStart specialist
Local time
Today, 07:19
Joined
Aug 16, 2003
Messages
239
OK,

I tried and found:

Put in the module of your report two Public variables for storing the page-numbers. You can set these with the event "Report_page", so if it's all in the module, copy this:
Code:
Option Compare Database
Option Explicit

Public intFirstPage As Integer
Public intLastPage As Integer

Private Sub Report_Page()
  intLastPage = Me.Page
  If intLastPage Mod 2 = 0 Then
    intFirstPage = intLastPage - 1
  Else
    intFirstPage = intLastPage
  End If
End Sub
Now when you navigate trough the report (in two-page-view), first and lastpage are stored.
For printint the report, you've to create a custom button or menu-option in your menu-/toolbar, that calls a public function for printing the report.
I tried it with the report "rptCompany", and created this function:
Code:
Public Function rptCompanyPrintPages()
  DoCmd.PrintOut acPages, Reports("rptCompany").intFirstPage, Reports("rptCompany").intLastPage
End Function
In a standard module!

From the button/menuoption, call rptCompanyPrintPages() and there are two pages printed out.
 

moose

c'mon Chelsea
Local time
Today, 06:19
Joined
May 18, 2001
Messages
139
Whilst I appreciate all the help from this excellent forum and it's Access Guru's knowledge, I am as you may have guessed not too hot on it as i am trying to learn it on my own with the help of you lot. my problem now is, you lost me when you said:-

SforSoftware said:
OK,

I tried and found:

Put in the module of your report two Public variables for storing the page-numbers. You can set these with the event "Report_page",

Can I use this code in conjunction with Macros as the whole db runs on them (mainly)?

if so, where would i put the code?

Sorry to be such a pain
 

moose

c'mon Chelsea
Local time
Today, 06:19
Joined
May 18, 2001
Messages
139
I have just discovered a problem with the TwoPagePreview command in the macro.
when there is data to show in the report it works fine but in the nodata event of the report, a macro is run to open a form letting the user know that there is no data and 2 command buttons.
in the event of there not being any data it still trys to run the TwoPagePreview command and falls over because the report doesn't open.
is there a way i can tell it to only run the TwoPagePreview command if the report is open?
 

SforSoftware

(NL) SnelStart specialist
Local time
Today, 07:19
Joined
Aug 16, 2003
Messages
239
moose said:
Can I use this code in conjunction with Macros as the whole db runs on them (mainly)?
It is possible, but I shouldn't do that.
If you want it to do with macro's, you have to build an extra form, with two fields, where you can store the pagenumbers. (you can do that with a SetValue).
With that, you've to look well at the conditions. Further, you must refer to the report with "Reports!ReportName.Page" instead of Me.Page.
Following actions are required:
- Opening the form (can be hidden)
- in the Page-event of the report: Set value (2 times for LastPage and FirstPage) with correct conditions
- Closing the hidden form when you close the report.

Problem is that you can't use the values of the hidden form in a macro-action PrintOut for the FirstPage and LastPage, so for calling the Print you still have to use code.
 

SforSoftware

(NL) SnelStart specialist
Local time
Today, 07:19
Joined
Aug 16, 2003
Messages
239
moose said:
is there a way i can tell it to only run the TwoPagePreview command if the report is open?
Yes, that might be a problem, but in the Conditions before the TwoPagePreview-command, you can check the recordsource for the report with a DCount I'd think? When it's a table or query that might be no problem, only when you open the report somewhere with a Where-statement.
I'd think this may be a question for a different thread in the macro-section of this forum.
 

moose

c'mon Chelsea
Local time
Today, 06:19
Joined
May 18, 2001
Messages
139
This sounds like it is getting well beyond me.
I get the feeling that i should've used code in the 1st place instead of macros but macros are fairly simple to write and code just seems to baffle me.

Would you be able to give me the code if i give you the names of the oblects involved

I'd be ever so grateful to you (Look at me, i'm groveling)
 

SforSoftware

(NL) SnelStart specialist
Local time
Today, 07:19
Joined
Aug 16, 2003
Messages
239
Hi,

Macro's are well, but code is better. Why? In code you can integrate your own errorhandlers, and you're far more flexible. It's worth to study...

The code you need can you exactly copy from my answer in this thread with the two code-samples. The first you've to put into the code-module of the report. After you've pasted it there, check that the property Page in the events of the reports says '[Event Procedure]' If not, then select it from the dropdownlist.

The second code-snippet can you paste in a standard-module. In that snippet you must change "rptCompany" in the name of your report.
You can call this function from a macro with the action "RunProcedure". In the argument you give:
rptCompanyPrintPages (that what is after "Public Function")
 

moose

c'mon Chelsea
Local time
Today, 06:19
Joined
May 18, 2001
Messages
139
i your last thread you put:-
SforSoftware said:
Hi,

......The code you need can you exactly copy from my answer in this thread with the two code-samples. The first you've to put into the code-module of the report. After you've pasted it there, check that the property Page in the events of the reports says '[Event Procedure]' If not, then select it from the dropdownlist.

The second code-snippet can you paste in a standard-module. In that snippet you must change "rptCompany" in the name of your report.
You can call this function from a macro with the action "RunProcedure". In the argument you give:
rptCompanyPrintPages (that what is after "Public Function")

where can i find 'code-module and do i just save the second module as anything?
 

SforSoftware

(NL) SnelStart specialist
Local time
Today, 07:19
Joined
Aug 16, 2003
Messages
239
1. The code-module.
Select the property "On Page" on the 'Events'-tab of the Report's properties. There select '[Event procedure]' from the dropdownlist. After that, press the small button after this field, and you'll come into the 'code module' of the report. There you can delete everyting and past the codesnippet I've given before.

2. No, the name of the module itself doesn't matter in this case, but give it a name that makes sense.
 

moose

c'mon Chelsea
Local time
Today, 06:19
Joined
May 18, 2001
Messages
139
i have put the following code into the on_page event of my report but when i try and view a report i get the error messages that i have attached for you to see

Private Sub Report_Page()
Option Compare Database
Option Explicit

Public intFirstPage As Integer
Public intLastPage As Integer

Private Sub Report_Page()
intLastPage = Me.Page
If intLastPage Mod 2 = 0 Then
intFirstPage = intLastPage - 1
Else
intFirstPage = intLastPage
End If
End Sub

I must be going wrong somwhere
 

Attachments

  • errors.zip
    50.3 KB · Views: 73

SforSoftware

(NL) SnelStart specialist
Local time
Today, 07:19
Joined
Aug 16, 2003
Messages
239
Yes, there's going something wrong ;)

Delete the very first line (Private Sub Report_Page() )
 

Users who are viewing this thread

Top Bottom