?
Solved

Selecting A Printer Using The Printer Dialog Control

Posted on 1998-06-17
7
Medium Priority
?
249 Views
Last Modified: 2010-05-03
I am having real problems assigning a printer to an object.  I can show the print dialog box but it doesn;t matter which printer is then selected by the user the default is always used.  I know I must be missing something obvious....but what?
0
Comment
Question by:WHITER
7 Comments
 

Expert Comment

by:cerik
ID: 1463515
do you do something like this

'Set flags to return hDC
'CommonDialog1.Flags = CommonDialog1.Flags + &H100
'this will cause a hDC to be returned
-------------
CommonDialog1.ShowPrinter
Debug.Print Printer.DeviceName
Printer.Print ""
Printer.EndDoc

the name of your selected printer should print in the debug window and a blank page
print out?

If this helps I will resubmit as an Answer
0
 

Author Comment

by:WHITER
ID: 1463516
Cerek,

It hasn't solved my problem, however I am struggling to come to terms with exactly whats going on here.  I have read the Microsoft literature and am still none the wiser as to what hDC actually does and how I use it.  

Your solution certainly caused an hDC to be returned but didn;t change my printer.devicename to the one selected.  Maybe I've missed the point somewhere?
0
 
LVL 2

Expert Comment

by:swilt
ID: 1463517
Cerik, does that change the default windows printer globally ?
0
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!

 

Author Comment

by:WHITER
ID: 1463518
Swilt/Cerik,

I do not have the printerdefault set to true, therefore any changes I make would be temporary.  
0
 
LVL 2

Expert Comment

by:swilt
ID: 1463519
You could create your on printer selection form

Code for test form

Option Explicit

Private Sub Command1_Click()
    frmPrintSel.Show vbModal
    If Not frmPrintSel.bCancel Then
        Printer.Print Printer.DeviceName
        Printer.EndDoc
    End If
End Sub


Code for frmPrintSel
    List1 - Listbox to display printers
    cmdOK - button to select a printer
    cmdCancel to cancel the operation


Option Explicit

Public bCancel As Boolean

Private Sub Form_Load()
    Dim i As Integer
   
    bCancel = True
    If Printers.Count = 0 Then
        List1.AddItem "No printers installed"
        CmdOk.Enabled = False
    Else
        For i = 0 To Printers.Count - 1
            List1.AddItem Printers(i).DeviceName
        Next i
    End If
End Sub

Private Sub cmdCancel_Click()
    Unload Me
End Sub

Private Sub CmdOk_Click()
    Dim i As Integer
   
    For i = 0 To List1.ListCount - 1
        If List1.Selected(i) Then
            Set Printer = Printers(i)
            bCancel = False
            Exit For
        End If
    Next i
    If bCancel Then
        MsgBox "You have not selected a printer", vbCritical, "Printer Selection"
    Else
        Unload Me
    End If
End Sub


0
 
LVL 1

Accepted Solution

by:
web_crusher earned 50 total points
ID: 1463520
if i understood right - you want to use a printer that is not a default
and you say - you have no default - here is an easy solution for you

with the api - writeprivateprofilestring() - you can set the device on the win.ini
to the printer you like and afterwards to delete it - this way - you are printing anytime with the device you like and no default is selected - easy
0
 

Author Comment

by:WHITER
ID: 1463521
Not bad Web_Crusher, However have you ever done this using the default printer dialog box provided with VB5?
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
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…
Suggested Courses
Course of the Month15 days, 8 hours left to enroll

850 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