Solved

commondialog.showprinter

Posted on 1998-11-18
3
2,069 Views
Last Modified: 2008-02-20
How does the showprinter method work.  It open the right dialog box, but when I press the OK button, it doesn't print anything.  Is there a way to send data to windows, or there is a way to catch the button selected.
0
Comment
Question by:DanielBlais
[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
 

Accepted Solution

by:
svfafel earned 100 total points
ID: 1445533
Daniel, the showprinter method is used to to set the appropriate printer just before you send data to the "Printer" object.  Here's a sample...(create a blank form and place a command button and a common dialog control on it)...

Private Sub Command1_Click()
CommonDialog1.ShowPrinter 'bring up the printer page
Printer.FontBold = True
Printer.Print "This is a test print"
Printer.Print ' this prints a blank line
Printer.Print "This is the second line"
Printer.Print
Printer.EndDoc  'this tells the printer object to flush the data that has been sent to it
End Sub

Two things to remember and to know...
#1 - Everything you want to print must be manually sent to the printer object.  (You can send graphics, lines, text, etc.)

#2 - You buffer everything in the printer object until you use the printer.enddoc statement

Hope this helps...
svfafel
0
 

Expert Comment

by:dream_vb
ID: 1445534
DanielBlais,
  the above answer is correct in some ways but not completly...you can do it that way or here is how you would print out a text box or a rich text box...

Private Sub mnu_print_Click()

    On Error Resume Next
'if there is an error ignore it and goto the next function

    CommonDialog1.CancelError = False
'makes it so when user presses Cancel it will not give an error

    CommonDialog1.DialogTitle = "dream_vb's Print Dialog"
'change that text to whatever you would like to...

    CommonDialog1.Flags = cdlPDReturnDC + cdlPDNoPageNums
'the flags.

    If text1.SelLength = 0 Then
        CommonDialog1.Flags = CommonDialog1.Flags + cdlPDAllPages
    Else
        CommonDialog1.Flags = CommonDialog1.Flags + cdlPDSelection
    End If
   
    If Cancel Then
    GoTo error
    Else
    CommonDialog1.ShowPrinter
    Printer.Print ""
    text1.SelPrint CommonDialog1.hDC
    End If
   
error: end

I hope that helps you out DanielBlais, mail me at dream_vb@juno.com for any further assistance...
0
 
LVL 2

Expert Comment

by:trillo
ID: 1445535
DanielBlais:

Hmmm..... I prepared this comment but I see that "dream_vb" was faster, anyway I'll post it.
The CommonDialog with the ShowPrinter methot only sets and retrieves information about the user's selection on the Print dialog... (It does not send anything automatically to the printer)
To know which button is selected, you must first set the CancelError property to true, this will fire an error when the user chooses the Cancel button or closes the Dialog (Erro with erronumber = 32755). Then you can place the code as in the following example:

Private Sub Command1_Click()
    On Error GoTo ErrorHandler
    cd.ShowPrinter
    MsgBox ("OK was pressed")
    Exit Sub
ErrorHandler:
    If Err.Number = 32755 Then
        MsgBox ("Cancel was pressed")
    End If
End Sub

I just tried it and it worked fine
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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…

729 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