Solved

Selecting A Printer Using The Printer Dialog Control

Posted on 1998-06-17
7
239 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

706 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

19 Experts available now in Live!

Get 1:1 Help Now