Printer dialog on acViewNormal

G

Guest

I have two buttons on a form that generates reports - one that previews
(acViewPreview), after which the user can click on a menu bar button to bring
up the printer dialog (I had to replace the standard printer button on the
menu bar with the one that brings up the printer dialog), and the other that
sends the print job straight to the printer (acViewNormal).

How can I, on my form, get the printer dialog to appear on printing
acViewNormal so that the user can choose a printer?
 
A

Allen Browne

Brian, you have probably already figured out that you can't open the printer
dialog after an OpenReport with acViewNormal, and you can't just open the
dialog before opening the report because it will apply to the wrong object.
Your requirements therefore require some sideways thinking.

How about having the report remember which printer the user wants to use?
You can do that by creating a custom property, and giving the user a toolbar
button to specify which printer to use. Next time the report is opened, you
can set the Printer object before you OpenReport.

For an example of how to do that, download the sample from:
Printer Selection Utility
at:
http://allenbrowne.com/AppPrintMgt.html
Note that this approach requires Access 2002 or 2003.
 
A

Albert D.Kallal

I simply create a menu bar, and then specify it for all my reports.

You can see a screen shot here:

http://www.members.shaw.ca/AlbertKallal/test/test.htm

The select object command is needed to fix a "focus" bug if you have a form
with a timer function.

For the code that pops up the printer dialog (so the user can change
printers etc).

You can use:


On Error Resume Next
DoCmd.SelectObject acReport, Screen.ActiveReport.Name
DoCmd.RunCommand acCmdPrint

The select object command is needed to fix a "focus" bug if you have a form
with a timer function.

The code to print right to the printer while in preview mode can be:

On Error Resume Next
Dim strReportName as string
strREportName = Screen.ActiveReport.Name
DoCmd.SelectObject acReport, strReportName
DoCmd.PrintOut acPrintAll


So, just have your two custom menu buttons call the above code.....
 
G

Guest

I may have to take a deeper look at both of these, but at a cursory glance, I
am not sure how this bypasses the print preview. I already use a custom menu
bar for all my reports, and its Print button is the brings up the print
dialog (I had to copy the alternate Print button from some other standard
menu to get the one with the print dialog attached).

My problem is more basic than this: how can I allow the user to choose the
printer on the fly directly from the form instead of in report preview. The
particular report that got me working on this is very complex and is run on
an almost daily basis; the user has to wait while the preview is generated,
then again while the report is printed. What I need to do is print the report
to the printer directly from the form; acViewNormal sends it directly to the
printer (no preview) without allowing the printer dialog.

Unless I missed something, the SelectObject does not work until the report
itself is open, which defeats the efficience gains I am seeking here.
 
G

Guest

Thanks, Allen. I was kind of trying to avoid all this manipulation, but I may
have to resort to it (or else just tell the user to change his default
printer so I don't have to deal with it...).

I have noticed in many other (non-Access) applications, that when one brings
up the print dialog, it sets a new "default" printer just for the environment
of the applicaiton's session. Some of these programs even have a way to just
bring up the printer dialog & select a printer that acts as the default while
the application is open. Are these done using a Windows API, or is it
something that I simply cannot access from Access?
 
G

Guest

As a followup to your code at the link, is there a way to query Windows for
the list of installed printers and present these as options in a list box so
that the

Set Application.Printer = Application.Printers("HP LaserJet Series II")

might read thus:

Set Application.Printer = Application.Printers([Forms]![myForm]![listBox1)

This is because I want to be able to distribute this application to various
users, and I will not know the names of their printers.
 
A

Allen Browne

Brian, you could easily offer a form that sets Application.Printer in
response to the user's choice.

That's a subset of the functionality offered in the suggested utility. It
would be quite simple to fill a combo or list box from Application.Printers,
let the user select one as their default for the session, and then Access
will print to that printer (unless you choose a Specific Printer under File
| Page Setup at design time.)
 
G

Guest

OK, let me have another crack at this. How about using a combo box,
populating its RowSource with a string concatenated from the list of
printers, and allowing the user to simply pick a printer? This remains the
session default, is that correct?

With prtSelect as the combo box:

Private Sub Form_Open()
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
End Sub

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

Am I headed the right direction, here? If so, I could pop up a tiny form in
acDialog that just has the combo box on it, thus allowing the user to select
a printer at runtime.
 
G

Guest

Thanks, Allen. While it would be nice to have a true printer dialog "look" to
the form, that is more work than I want to do. Your code got me headed down
the right path, I think, and just before I saw your answer, I posted some
sample code to do just that.

Thanks again.
 
A

Albert D.Kallal

As a followup to your code at the link, is there a way to query Windows
for
the list of installed printers and present these as options in a list box
so
that the

I see that you found a solution. I did not realize that you did NOT want to
launch the report.....

Your idea to load up combo box with the printers is the simple solution...
 
B

Brian

Allen,

I am just revisiting this issue on another project, where my custom printer
selection form, although fairly efficient, just does not look as good or
function as well as the standard Windows printer selecton dialog.

I am just wondering if there have been any changes that allow one to use the
standard Windows printer selection dialog window, then pass the printer
selection to a report that is not yet open and needs to be printed without
being previewed.

I am probably displaying my ignorance of the Windows print methods once
again . I suppose the Windows printer dialog needs the page layout of the
actual object (i.e. the report), not a theoretical object to be handed to it
after the selection is made, but I can always hope something has changed.
 

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