Print and Print Preview (1 Viewer)

Lkwdmntr

Registered User.
Local time
Today, 00:31
Joined
Jul 10, 2019
Messages
277
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?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 00:31
Joined
Oct 29, 2018
Messages
21,358
So, why not just comment out the last two lines and only use the first line? Just curious...
 

isladogs

MVP / VIP
Local time
Today, 07:31
Joined
Jan 14, 2017
Messages
18,186
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
 

Lkwdmntr

Registered User.
Local time
Today, 00:31
Joined
Jul 10, 2019
Messages
277
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​
 

theDBguy

I’m here to help
Staff member
Local time
Today, 00:31
Joined
Oct 29, 2018
Messages
21,358
Hi. What happens if you simply did it this way?
Code:
[INDENT]Private Sub Print_Click()
    
     DoCmd.OpenReport "WeekataGlance_RPT", acViewPreview

End Sub[/INDENT]
 

Gasman

Enthusiastic Amateur
Local time
Today, 07:31
Joined
Sep 21, 2011
Messages
14,050
Do you have an On Error statement?
 

isladogs

MVP / VIP
Local time
Today, 07:31
Joined
Jan 14, 2017
Messages
18,186
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
 

Lkwdmntr

Registered User.
Local time
Today, 00:31
Joined
Jul 10, 2019
Messages
277
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.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 00:31
Joined
Oct 29, 2018
Messages
21,358
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...
 

Lkwdmntr

Registered User.
Local time
Today, 00:31
Joined
Jul 10, 2019
Messages
277
Just went over this with my boss and she agrees with the short cut. Thanks, nice solution.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 00:31
Joined
Oct 29, 2018
Messages
21,358
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.
 

Users who are viewing this thread

Top Bottom