Solved

Print with Commondialog?

Posted on 2000-04-19
3
232 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…

810 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