Solved

Changing printer settings

Posted on 2000-03-13
6
167 Views
Last Modified: 2010-05-02
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?
0
Comment
Question by:mi5
  • 4
6 Comments
 
LVL 1

Accepted Solution

by:
fbtcell earned 25 total points
ID: 2611534
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
 
LVL 1

Expert Comment

by:MitchBroadhead
ID: 2611547
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
 
LVL 1

Expert Comment

by:MitchBroadhead
ID: 2611550
Oh yeah

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

so just use printer.print
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

Author Comment

by:mi5
ID: 2611566
How do I use this dialog to change the printer settings and print the contents of my form on the selected printer?
0
 
LVL 1

Expert Comment

by:MitchBroadhead
ID: 2611608
form1.PrintForm

The printer should have already been selected by the print dialog box (otherwise the cancel error would have been raised)
0
 
LVL 1

Expert Comment

by:MitchBroadhead
ID: 2611612
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

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question