Go Back   Access World Forums > Microsoft Access Discussion > Reports

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 10-25-2019, 07:45 AM   #1
Lkwdmntr
Newly Registered User
 
Join Date: Jul 2019
Posts: 105
Thanks: 2
Thanked 0 Times in 0 Posts
Lkwdmntr is on a distinguished road
Print and Print Preview

Hello,
I'm running into a problem when I pull up a report to print. I want to view it first and then have the option to print the report. This is the code I am using right now.
DoCmd.OpenReport "Thu_Reporting_Form", acViewPreview
DoCmd.RunCommand acCmdPrint
DoCmd.Close acReport, "Thu_Reporting_Form"
This does pull up the report but it is blank and the print options box is in the middle of the screen. In order for me to see the report, I have to print it first. If I hit cancel it gives me a "Runtime error 2501" the RunComand action was canceled.

I would like to see the report first and then have the option to print, and if I do hit the cancel button, is there a way to avoid the error popping up and just stay on the report view?

Lkwdmntr is offline   Reply With Quote
Old 10-25-2019, 07:51 AM   #2
theDBguy
Iím here to help
 
theDBguy's Avatar
 
Join Date: Oct 2018
Location: SunnySandyEggo
Posts: 6,521
Thanks: 58
Thanked 1,424 Times in 1,405 Posts
theDBguy has a spectacular aura about theDBguy has a spectacular aura about
Re: Print and Print Preview

So, why not just comment out the last two lines and only use the first line? Just curious...
__________________
Just my 2 cents...

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
theDBguy is online now   Reply With Quote
Old 10-25-2019, 07:52 AM   #3
isladogs
High Noon Moderator
 
isladogs's Avatar
 
Join Date: Jan 2017
Location: Somerset, UK
Posts: 11,284
Thanks: 115
Thanked 3,088 Times in 2,806 Posts
isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold
Re: Print and Print Preview

Just use the first line of your code then use the Print Preview ribbon to print the report.


Use error handling in your form to manage error 2501. This is an example from one of my forms....
Code:
Exit_Handler:
    Exit Sub

Err_Handler:
    If Err.Number = 2501 Then Exit Sub
    MsgBox "Error " & Err.Number & " in cmdPrint_Click procedure : " & Err.Description
    Resume Exit_Handler

__________________
If this answer has helped, please click the Thanks button and/or click the 'reputation scales' symbol on the left.

Colin (Mendip Data Systems)
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


Website links:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


Common sense and a sense of humour are the same thing, moving at different speeds. (Clive James - RIP)
isladogs is offline   Reply With Quote
Old 10-25-2019, 08:26 AM   #4
Lkwdmntr
Newly Registered User
 
Join Date: Jul 2019
Posts: 105
Thanks: 2
Thanked 0 Times in 0 Posts
Lkwdmntr is on a distinguished road
Re: Print and Print Preview

Nice tip, but I don't think I'm using this properly. This is where I put the code and I still get the error box.
Private Sub Print_Click()

DoCmd.OpenReport "WeekataGlance_RPT", acViewPreview
DoCmd.RunCommand acCmdPrint
Exit_Handler:
Exit Sub

Err_Handler:
If Err.Number = 2501 Then Exit Sub
MsgBox "Error " & Err.Number & " in cmdPrint_Click procedure : " & Err.Description
Resume Exit_Handler

End Sub
Lkwdmntr is offline   Reply With Quote
Old 10-25-2019, 08:31 AM   #5
theDBguy
Iím here to help
 
theDBguy's Avatar
 
Join Date: Oct 2018
Location: SunnySandyEggo
Posts: 6,521
Thanks: 58
Thanked 1,424 Times in 1,405 Posts
theDBguy has a spectacular aura about theDBguy has a spectacular aura about
Re: Print and Print Preview

Hi. What happens if you simply did it this way?
Code:
Private Sub Print_Click() DoCmd.OpenReport "WeekataGlance_RPT", acViewPreview End Sub
__________________
Just my 2 cents...

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
theDBguy is online now   Reply With Quote
Old 10-25-2019, 08:33 AM   #6
Gasman
Enthusiastic Amateur
 
Gasman's Avatar
 
Join Date: Sep 2011
Location: Swansea, South Wales,UK
Posts: 4,525
Thanks: 441
Thanked 841 Times in 812 Posts
Gasman is a jewel in the rough Gasman is a jewel in the rough Gasman is a jewel in the rough
Re: Print and Print Preview

Do you have an On Error statement?
__________________
Access novice. Sometimes trying to give something back.
Access 2007

Please, please use code tag # when posting code snippets

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Gasman is online now   Reply With Quote
Old 10-25-2019, 08:44 AM   #7
isladogs
High Noon Moderator
 
isladogs's Avatar
 
Join Date: Jan 2017
Location: Somerset, UK
Posts: 11,284
Thanks: 115
Thanked 3,088 Times in 2,806 Posts
isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold
Re: Print and Print Preview

As the last two posts indicate, you aren't doing it correctly

Just to check, is this for a button called Print on your form?

You need to add the On Error line below
I've also removed the acCmdPrint line

Code:
Private Sub Print_Click()

On Error GoTo Err_Handler
    
DoCmd.OpenReport "WeekataGlance_RPT", acViewPreview

Exit_Handler:
    Exit Sub

Err_Handler:
    If Err.Number = 2501 Then Exit Sub
    MsgBox "Error " & Err.Number & " in Print_Click procedure : " & Err.Description
    Resume Exit_Handler

End Sub

__________________
If this answer has helped, please click the Thanks button and/or click the 'reputation scales' symbol on the left.

Colin (Mendip Data Systems)
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


Website links:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


Common sense and a sense of humour are the same thing, moving at different speeds. (Clive James - RIP)
isladogs is offline   Reply With Quote
Old 10-25-2019, 09:51 AM   #8
Lkwdmntr
Newly Registered User
 
Join Date: Jul 2019
Posts: 105
Thanks: 2
Thanked 0 Times in 0 Posts
Lkwdmntr is on a distinguished road
Re: Print and Print Preview

So the big boss wants all the forms and report views to be "Full Screen", that means, she doesn't want to see the behind the scenes work being done. It is like she is simply running an application, not seeing anything to do with access at all. She will never have the ribbon on top to access the print option.

I hope that clarifies why I am not using the advice given so far.
Lkwdmntr is offline   Reply With Quote
Old 10-25-2019, 09:53 AM   #9
theDBguy
Iím here to help
 
theDBguy's Avatar
 
Join Date: Oct 2018
Location: SunnySandyEggo
Posts: 6,521
Thanks: 58
Thanked 1,424 Times in 1,405 Posts
theDBguy has a spectacular aura about theDBguy has a spectacular aura about
Re: Print and Print Preview

Quote:
Originally Posted by Lkwdmntr View Post
So the big boss wants all the forms and report views to be "Full Screen", that means, she doesn't want to see the behind the scenes work being done. It is like she is simply running an application, not seeing anything to do with access at all. She will never have the ribbon on top to access the print option.

I hope that clarifies why I am not using the advice given so far.
In that case, would she also be opposed to using a keyboard shortcut? Just curious...
__________________
Just my 2 cents...

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
theDBguy is online now   Reply With Quote
Old 10-25-2019, 12:23 PM   #10
Lkwdmntr
Newly Registered User
 
Join Date: Jul 2019
Posts: 105
Thanks: 2
Thanked 0 Times in 0 Posts
Lkwdmntr is on a distinguished road
Re: Print and Print Preview

Just went over this with my boss and she agrees with the short cut. Thanks, nice solution.
Lkwdmntr is offline   Reply With Quote
Old 10-25-2019, 12:25 PM   #11
theDBguy
Iím here to help
 
theDBguy's Avatar
 
Join Date: Oct 2018
Location: SunnySandyEggo
Posts: 6,521
Thanks: 58
Thanked 1,424 Times in 1,405 Posts
theDBguy has a spectacular aura about theDBguy has a spectacular aura about
Re: Print and Print Preview

Quote:
Originally Posted by Lkwdmntr View Post
Just went over this with my boss and she agrees with the short cut. Thanks, nice solution.
Hi. Glad to hear it worked out. Good luck with your project.

__________________
Just my 2 cents...

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
theDBguy is online now   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
logo's on report print preview differs from print pdf lcarpay Reports 4 05-10-2018 02:49 AM
Unbound Report - Print Preview OK but Direct to Print Fails sgrace Reports 3 05-26-2013 02:47 PM
Report header looks good in print preview but doesn't print bumblingidiot Reports 8 02-16-2012 01:15 PM
Geting the Print window to open while in print preview. PuddinPie Reports 5 08-14-2011 11:11 PM
Access button to print report instead of opening it in print preview vvangogh Modules & VBA 2 07-01-2011 10:45 AM




All times are GMT -8. The time now is 10:07 AM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World