Link to home
Start Free TrialLog in
Avatar of DanielBlais
DanielBlaisFlag for Canada

asked on

commondialog.showprinter

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.
ASKER CERTIFIED SOLUTION
Avatar of svfafel
svfafel

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dream_vb
dream_vb

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...
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