Changing printer settings

Using 'form1.print' I can print the contents of a form. How do I show the user the printer dialog box so that they can select a printer and change the print options?
mi5Asked:
Who is Participating?
 
fbtcellConnect With a Mentor Commented:
On your form create a CommonDialog (ex : MyDiag), and put the following code in your form (for the btPrinterSetUp button for example) :

Private Sub btPrinterSetUp_Click()
diagSys.ShowPrinter
End Sub

diagSys.ShowPrinter will call for you the setup printer dialog.
0
 
MitchBroadheadCommented:
remember to use the cancel error:

on error resume next
diagsys.CancelError = true
diagsys.caption = "Print something"
diagsys.showprinter

if err = 0 then
    Printfile(diagsys.Filename)
else
    'Cancel button was pressed
endif
 
0
 
MitchBroadheadCommented:
Oh yeah

the printewr dialog just sets printer = to the printer in question

so just use printer.print
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
mi5Author Commented:
How do I use this dialog to change the printer settings and print the contents of my form on the selected printer?
0
 
MitchBroadheadCommented:
form1.PrintForm

The printer should have already been selected by the print dialog box (otherwise the cancel error would have been raised)
0
 
MitchBroadheadCommented:
The final code should look like this:

sub cmdPrintForm_Click()

on error resume next

diagsys.CancelError = true
diagsys.caption = "Print something"
diagsys.showprinter

if err = 0 then
    form1.PrintForm
else
    'Cancel button was pressed
endif

end sub
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.