Solved

Print with Commondialog?

Posted on 2000-04-19
3
241 Views
Last Modified: 2010-05-02
How can I print using a common dialog form? Here's my code. Can you tell my why it doesn't work?

Private Sub mnuPrint_Click()
Dim BeginPage, EndPage, NumCopies, Orientation
   ' Set Cancel to True.
   CD1.CancelError = True
   On Error GoTo ErrHandler
   ' Display the Print dialog box.
   CD1.Action
   CD1.ShowPrinter
   ' Get user-selected values from the dialog box.
   BeginPage = CD1.FromPage
   EndPage = CD1.ToPage
   NumCopies = CD1.Copies
   Orientation = CD1.Orientation
   Printer.Copies = NumCopies
   Printer.Orientation = Orientation
   Printer.Print Main.Text
   Exit Sub
ErrHandler:
   ' User pressed Cancel button.
End Sub
0
Comment
Question by:RogueAce
3 Comments
 
LVL 4

Expert Comment

by:PBuck
ID: 2732524

'Place your error handling first.
On Error GoTo ErrHandler

frmMain.CommonDialog1.CancelError = True
frmMain.CommonDialog1.Flags = &H10& Or &H200&
frmMain.CommonDialog1.Action = 5  'Show printer box

'Set your action to CODE number 5

'Your code here looks good
' Get user-selected values from the dialog box.
   BeginPage = CD1.FromPage
   EndPage = CD1.ToPage
   NumCopies = CD1.Copies
   Orientation = CD1.Orientation

   Printer.Copies = NumCopies
   Printer.Orientation = Orientation
   
'Use a for-next loop for the copies  
For i = 1 To NumCopies
    Printer.Print frmMain.Text1.Text
Next i

'Then your final code looked good also
   Exit Sub
ErrHandler:
   ' User pressed Cancel button.

Well Done.  I help this helps you get going.  Good Luck!
0
 

Accepted Solution

by:
sevenofnine earned 100 total points
ID: 2732530
You may need to get rid of the CD1.Action line(I couldn't get this to work).  You are 99% of the way there - you just need to add Printer.EndDoc after Printer.Print - you had already sent the document to the print queue, it just needed to be "released" as it were.
Hope that helps!
0
 
LVL 1

Author Comment

by:RogueAce
ID: 2749161
Thanks for the info. As 7 of 9 said, there does have to be an EndDoc statement after the printing code for optimal print handling.

Thank you again.
Rogue
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

840 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