Printing to a specific printer/Using the Print Dialog Window

D

David C. Holley

I've figured out that the following code can be used to change the
default printer to a specific printer and then backagain using
strOldPrinter.

Sub changePrinter(strPrinterName As String)

strOldPrinter = Application.Printer.DeviceName
Application.Printer = Application.Printers(strPrinterName)

End Sub

Now the question at hand is how do I call the Print Dialog Window if I
need the user to select a printer such as when the printer supplied
doesn't exist or is misspelled? I'm assuming that using the window is
essentially the same as the Windows Common Dialog.

David H
 
G

Guest

Not sure if you need the first 2 lines of my code but line 3 opens the print
dialog box

Dim myreport As Report
Set myreport = Screen.ActiveReport
DoCmd.DoMenuItem 1, 0, 10
 
D

David C. Holley

I'll be using the WindowsAPI. Since for some reason which I have no idea
about, I'm hesitant to use DoMenuItem.
 
D

David C. Holley

I need the Print Dialog Window since I need the ability to capture the
name of the printer selected prior to printing.
 
D

David C. Holley

Well its now a moot point because I just realized that I can use a form
with a list box loaded with the printer names and grab things from
there. Much easier than trying to adapt code or actually using the Print
Dialog window.
 
G

Guest

David,

Are you getting the printer list from the lWindows ist of installed
printers, or from a list that you manually store somewhere (i.e. knowing
which printers are installed)?

I am trying to allow users to select a printer at runtime with a
non-previewed report (it is a big one that is run almost daily, so the users
need to be able to select the printer at runtime, but not have to wait for
the preview, which effectively doubles the length of time it takes before the
printout actually arrives at the printer).

I guess I don't understand why there isn't just an API. It takes all of one
line of code to open the Add Printer wizard; why is it so painful trying to
open a printer selection dialog outside of acViewPreview?
 
D

David C. Holley

The mind is pretty much green jello at this point. If I recall
correctly, I was using the Printers collection of the Application object
to get the list of installed printers an populate a TreeView control
from there.
 
G

Guest

I finally figured it out one way: open a very small form in dialog mode, in
its Open event, build a RowSource for a combo box by concatenating the
printers collection names, and in the AfterUpdate of the combo box, set the
application printer to the selected printer - a poor man's print dialog.

Here it is, for anyone that happens to read this thread later (like me, the
next time I need it and have forgotten how I did it):

Private Sub Form_Open(Cancel As Integer)
Dim prtCount As Integer
Dim prtCurrent As Integer
Dim prtName As String
Dim prtList As String
prtCount = Application.Printers.Count
If prtCount = 0 Then Exit Sub
For prtCurrent = 0 To prtCount - 1
prtName = Application.Printers(prtCurrent).DeviceName
If prtCurrent = 0 Then
prtList = prtName
Else
prtList = prtList & ";" & prtName
End If
Next prtCurrent
prtSelect.RowSource = prtList
prtSelect.SetFocus
prtSelect.Dropdown
End Sub

Private Sub prtSelect_AfterUpdate()
If Not IsNull(prtSelect) Then Set Application.Printer =
Application.Printers("" & prtSelect & "")
DoCmd.Close
Exit Sub
End Sub

(I also have a close button on this little form in case the user elects to
not select a different printer.) Now, from the main form from which I want to
call the print job, I just do these two lines:

DoCmd.OpenForm "PrinterSelect", acNormal, , , , acDialog 'opens the homemade
print dialog
DoCmd.OpenReport ReportName, acViewNormal, , strWhere 'prints report to
selected printer
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top