Solved

Print with Commondialog?

Posted on 2000-04-19
3
247 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

751 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