Solved

Print with Commondialog?

Posted on 2000-04-19
3
222 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
Comment Utility

'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
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now