[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

commondialog.showprinter

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses

649 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