Solved

Selecting A Printer Using The Printer Dialog Control

Posted on 1998-06-17
7
245 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
[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
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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

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

Industry Leaders: 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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…

724 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