Print Dialog Box

S

Stuart Grant

How can I call up the standard Windows Print Dialog Box through code before
printing a report ?
I have a Form with a Print command button which runs a small sub which runs
DoCmd.OpenReport and prints out the list, but I would like to see in advance
how many pages there are, perhaps only print a few and set up a Brother 5040
to do Duplex printing through the Printer Preferences on the Print Dialog
Box beforehand.
Is this possible ?
Stuart
 
D

David PONDA

Hi,
if you can load a standard open dialogue box, it a samething just change the
methode
1. add a CommonDialog ActiveX control in your form
2. the code :
With CommonDialog1
.DialogTitle = "Dialog Box Title"
.Filter = "DBase CyberSite (*.mdb)|*.mdb" '*** Filter name
.InitDir = App.Path '***
Init folder
.ShowPrinter
End With

Try it... and recontact me for any further infos.
Dave
 
S

Stuart Grant

Douglas

Thank you but this produces a wrong syntax error message. In hunting
previously in MSDN I think I saw somewhere that this command had been
changed after Access 97 but I could not understand the revision !

Stuart
 
S

Stuart Grant

David

Thank you for your suggestion. I managed toadd a CommonDialog ActiveX
control to the form. From the Property Sheet its name seemed to be
CommonDialog3.

I am afraid I do not understand your code. What is the point of making the
property DialogTiltle = "Dialog Box Title" ?
What is this Filter "DBaseCyberSite(*.mdb)*.mdb. The Form is based on a
Query and does not have a filter.

I added to the code the line
CommonDialog3.ShowPrinter (although ShowPrinter is not one of the automatic
options offfered by Access)
Bingo! Up came the Printer Dialog Box ! But it did not offer the option of
selecting the pages to print and did not say how many pages there were. I
think I have to get into the code the name of the report, before calling the
dialog box.
The report is just called "Address List".

Stuart
 
D

Douglas J. Steele

What version of Access are you using? I'm afraid I only have Access 97
available for testing at the moment, but MSDN implies that acCmdPrint is
still a valid option for RunCommand in Access 2002 and Access 2003.

What exactly did you do with that line of VBA?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Stuart Grant said:
Douglas

Thank you but this produces a wrong syntax error message. In hunting
previously in MSDN I think I saw somewhere that this command had been
changed after Access 97 but I could not understand the revision !

Stuart
 
S

Stuart Grant

Douglas

My apologies. I am using Access 2003 and you are of course right.
acCmdPrint is a valid command in Access 2003

The problem is that I don't want to print the Form. I want to print a
Report "Address List", totally based on the form.
The button is on the form as cmd Print.

In my original code, I have

Dim stDocName As String
stDocName = "Address List"
DoCmd.OpenReport stDocName , acNormal

This works fine. Prints out perfectly but I do not get the Print Dialog
box. to select only some pages and to set duplex printing. If I try
DoCmd.RunCommand, it gives me the dialog box, allows me to select page and
set duplex printing but it prints the form, not the report.

I tried after your suggestion

DoCmd.RunCommand stDocName acCmdPrint

and this produced the syntax error and if I try to add the stDocName at the
end of the command I get a Compile Error.

Is there a way of doing what I want ?

Stuart
 
D

Douglas J. Steele

Try opening the report in Preview mode:

DoCmd.OpenReport stDocName , acPreview

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Stuart Grant said:
Douglas

My apologies. I am using Access 2003 and you are of course right.
acCmdPrint is a valid command in Access 2003

The problem is that I don't want to print the Form. I want to print a
Report "Address List", totally based on the form.
The button is on the form as cmd Print.

In my original code, I have

Dim stDocName As String
stDocName = "Address List"
DoCmd.OpenReport stDocName , acNormal

This works fine. Prints out perfectly but I do not get the Print Dialog
box. to select only some pages and to set duplex printing. If I try
DoCmd.RunCommand, it gives me the dialog box, allows me to select page and
set duplex printing but it prints the form, not the report.

I tried after your suggestion

DoCmd.RunCommand stDocName acCmdPrint

and this produced the syntax error and if I try to add the stDocName at
the end of the command I get a Compile Error.

Is there a way of doing what I want ?

Stuart
 
S

Stuart Grant

Douglas

Thank you.

DoCmd.OpenReport stDocName , acPreview

followed by

DoCmd.RunCommand acCmdPrint

works fine.

It gives me a preview on the screen which I do not really need but I can
always close it.

Thanks again.

Stuart
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top