Solved

commondialog.showprinter

Posted on 1998-11-18
3
2,059 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
3 Comments
 

Accepted Solution

by:
svfafel earned 100 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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 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…
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…

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