Print Dialog Box

rube

Registered User.
Local time
Today, 08:18
Joined
Jun 21, 2003
Messages
76
How do you use the Print Dialog Box with a Report?

I do not want to put the code in the report itself.

I added a Common Dialog Box, and it works, except if the user hits cancel, it then prints anyway. I have about 8 good Access Books but they do not discuss the Print Dialog Box except in passing.


The Code I am using works, except for Cancel. If I hit cancel, it prints the Report anyway.

dglPrint.ShowPrinter
DoCmd.OpenReport stDocName, acNormal

I tried to use RunCommand acCmdPrint, but it printed the screen like I hit File | Print.

I appreciate any input.

Thanks,

Chris.
 
Chris,

Your code is Perfect for the OK button.

The Cancel should just have: DoCmd.Close

Wayne
 
Chris,

Another option:
in the Caption property of the report, enter "Ctrl + P to print".

Then open the report in view mode. The user will see "Ctrl + P to print" in the top of the view window. The user can key "Ctrl +P" to open the print dialog window.

RichM
 
Print Dialog

The problem with the cancel is, how do I call it and keep my Report from printing out?


cmdPrint_Click

dglPrint.ShowPrinter
DoCmd.OpenReport stDocName, acNormal

exit sub

assuming I have Error Handling in here, this will bring up the Print Dialog Box, and wait for the user to press print, cancel, pages etc. This all works, except when the user hits Cancel. (On the dialog box). It cancels the Print Dialog box, but then the Report still prints out. (from the Docmd.OpenReport.....)

I want the Dialog Box to Pop up, they make their choice and it either print out or cancel. I do not know where to put my close command as a result of someone pressing Cancel. I have looked in all my books, none have any detail on Print Common Diaolog or RunCmdAcPrint.

Thanks for your input...
 
rube,

In the OnClick of the Cancel button, just do a DoCmd.Close.

It will not even try to run the report.

Wayne
 
Thanks for the input. I understand both of the emails you sent, if I built the Print Dialog Box, I could put a condition to whether the Report is called to print or not.

The problem is, I inserted a Microsoft ActiveX control a Common dialog Box named dlgPrinter. To show this, I use the

dlgPrinter.ShowPrinter

There is not (at least I don't know), an option to access the physical Dialog Box, it comes up but I did not create it as I would a Command Button for Print and a Command Button for Cancel. The only option I see is

cdlPrinter.Cancel

I do not know how to use this or what coded is needed to cancel the OpenReport Command. I tried using On Cancel, Case, If, etc. with this but was unsuccessful...

Any thoughts?
 
Print Dialob

I found the code.

Private Sub cmdPrintTest_Click()

On Error GoTo ErrorTrap

DoCmd.SelectObject acReport, "reportprinttest", True
DoCmd.RunCommand acCmdPrint



ErrorTrap:
If Err.Number = 2501 Then
Exit Sub
Else
MsgBox Err.Description
End If

End Sub

Thanks for the input.
 
Nice job rube,

I searched on this (and other) forums and found no info
on "dlgprinter".

Wayne
 
Print Dialog

Thanks for looking. The cdlPrint, is the name of my Microsoft Print Dialog Control. It actually should be dlgPrint (for dialog) I believe is the convention they use. I still would prefer to use this over the acCmdPrint, but I can still find no code covering the use. I found the 2501 Error code on another site that linked back to a MS KnowBase, 2501 is given whenever the user hits cancel, so you exit the sub.

I prefer the look of the MSDialog box over the box that pulls with the acCmdPrint.

Again, I appreciate your time and input.

Chris.
 
Print Dialob

I found the code.

Private Sub cmdPrintTest_Click()

On Error GoTo ErrorTrap

DoCmd.SelectObject acReport, "reportprinttest", True
DoCmd.RunCommand acCmdPrint



ErrorTrap:
If Err.Number = 2501 Then
Exit Sub
Else
MsgBox Err.Description
End If

End Sub

Thanks for the input.
Save me a lot of time, 11 years later..
 
Save me a lot of time, 11 years later..

Which is EXACTLY why we ask people to discuss or show their solutions. You never know when that code will solve another problem later.
 

Users who are viewing this thread

Back
Top Bottom