?
Solved

commondialog.showprinter

Posted on 1998-11-18
3
Medium Priority
?
2,070 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 200 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

Technology Partners: 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

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 …
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
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…
Suggested Courses
Course of the Month9 days, 6 hours left to enroll

764 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