Print report using selected printer

B

Bruce

This duplicates part of an earlier post in the Getting
Start forum, but after a couple of days I have not
received a reply, so I am reposting here.
I have recently received help from this newgroup in
setting up a form and printing the related report. I used
the wizard to set up the command button to print the
report, then incorporated suggestions until I came up with
the following:

Private Sub cmdPrintForm_Click()

'Open the report to display only the current record

Dim DocName As String
Dim LinkCriteria As String

stLinkCriteria = "[ID]=" & Me![ID]
stDocName = "rptSpecReview"
DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenReport stDocName, acNormal, , stLinkCriteria

Exit Sub
End Sub

cmdPrintForm is the command button on the form, [ID] is
the autonumber unique identifier for the record, and
rptSpecReview is the report that is printed.
The code above works fine in printing the report on the
default printer. However, different users in different
parts of the facility will be printing this form, and I
would like them to be able to choose a printer. How can
this be done?
I can place on the form a button to preview the report,
but when it comes time to print there are some issues.
There is no ready method for putting a Print button on the
report (somebody suggested code to add a floating toolbar,
but that is somewhat cumbersome, and anyhow I couldn't get
it to work). I know the user can print from a toolbar
button, so this is not a big concern. However, the print
command defaults to printing all records, and even when
Selected Record is checked in the print dialog (more user
input than I would like to have anyway), the page
numbering is for all of the records, so that the first
page of the selected record might show as Page 11 of 33 or
something.
Ideal situation would be for the user to preview the
report for the selected record, then print it with page
numbering such that the first page of any record is Page 1.
Almost as good would be for the user to click on the
command button described above, select a printer, and have
the report print with numbering as described in preceding
sentence. Previewing the form before printing would be
nice, but is not required.
 
A

Albert D. Kallal

However, the print
command defaults to printing all records, and even when
Selected Record is checked in the print dialog.

Hum, that is strange. Try changing the following:

DoCmd.OpenReport stDocName, acNormal, , stLinkCriteria

To

DoCmd.OpenReport stDocName, acViewPreview, , stLinkCriteria

That should give you a report that starts at page 1, with the current
record. In fact, it will ONLY give you the one record in the report. If you
hit the printer icon on the tool bar, then you should ONLY get the one
record.

Note that also when you go file->print, you will always get the printer
dialog to pop up. If you hit the printer icon on the tool bar, then the
report will print as is (no printer dialog). However, in both cases, it
should NOT print all records.

So, try both of the above. This approach should NOT mess up your page
numbering.

Good luck. Feel free to expand your questions on the above if you need be.
 
B

Bruce

Again, there are so many facets to this that I leave
things out. The preview button that I added with the
wizard is the one that seems to default to printing every
record. The code you provided in your last posting solves
the problem of the preview showing numbering for all of
the records (11 of 33, etc.), so I will attach it to the
preview button in place of what is there now. The code in
the first posting in this thread causes the selected
record to print to the default printer with the proper
page numbering. That is good. I can live with that.
However, if it is possible to choose printers from that
command button, that would be even better. Thanks for
your help.
 
A

Albert D. Kallal

My newsreader missed this yesterday...so, I am responding a bit late here!
However, if it is possible to choose printers from that
command button, that would be even better. Thanks for
your help.

Hum, ok. Note that with the report in preview mode, going file->print does
give the user the option to select a printer. This approach is not perfect,
but users usually can deal with this approach.

So, after the report is displayed in preview mode, do we:

a) let the user view, and look. They can close the report.
If user wants to print, they go file->print and can choose
the printer dialog.

b) Open the report, and immediately give the user the printer
selection dialog?

c) ask user what printer, and print without preview.

I certainly prefer option "a", since the user may just want to view the
report and not print (no use bugging the user each time for which printer).
Further, with option "a", then user can hit the print icon on the menu bar,
and NO printer prompt occurs. If they go file->print, then they get the
printer selection dialog. This is exactly how word, and Excel work. You hit
the cute printer icon, and it prints. You go file->print, and you get the
printer dialog. So, for this reason I kind also like option "a)", since it
works like word and excel.

You can however pop up the standard printer dialog in code if wish, but I
not 100% sure which of the above 3 options you want.

I am not sure which of the above you want. note that if you want to ask for
which printer BEFORE launching the report, then you need to use your OWN
code to switch the printer. You can certainly do that, but then you are
making your own printer selection code. If using a2002, then you can set the
printer very easy in code. If using a earlier version of ms-access, then you
can grab my sample printer switch code at:

http://www.attcanada.net/~kallal.msn/msaccess/msaccess.html

Feel free to mention/ask which of the 3 options you prefer. You can
show/display the printer select dialog with the following code:

DoCmd.SelectObject acReport, "report name"
DoCmd.RunCommand acCmdPrint

The above works if the report is already in preview mode.
 

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