Solved

Selecting A Printer Using The Printer Dialog Control

Posted on 1998-06-17
7
240 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…

910 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

22 Experts available now in Live!

Get 1:1 Help Now