Access prints form instead of report!!

B

Brian

When my users click the "Print" button, it runs VBA code as such:

DoCmd.OpenReport ReportName, acViewPreview, , , acWindowNormal
On Error Resume Next
DoCmd.SelectObject acReport, ReportName
DoCmd.RunCommand acCmdPrint
DoCmd.Close acReport, ReportName, acSaveNo

What is wrong with this code that would make Access print the form on the
screen as opposed to the report sitting in the background in Preview???

Thanks for anyone's help!
 
B

Brian

The reason for the rest of the code is because I want the standard Windows
print box to popup to allow my users to select their printer. Does the
DoCmd.PrintOut command call up the Windows print box?

If there is another way of doing this by using the acNormal command, let me
know.
 
D

Dirk Goldgar

Brian said:
The reason for the rest of the code is because I want the standard Windows
print box to popup to allow my users to select their printer.

I see. That makes sense to me now.
Does the DoCmd.PrintOut command call up the Windows print box?

I don't think so.
If there is another way of doing this by using the acNormal command, let
me
know.

There's a somewhat elaborate way, but your method does seem as though it
ought to work, and it's simple. I just tried it with a simple report, using
your code exactly as posted,. and it printed the report successfully -- not
the form. So maybe it's print command was sent. Did you try adding the
DoEvents statement as I suggested?

Also, I tested this with Access 2003. What version of Access are you using?
 
F

fredg

The reason for the rest of the code is because I want the standard Windows
print box to popup to allow my users to select their printer. Does the
DoCmd.PrintOut command call up the Windows print box?

If there is another way of doing this by using the acNormal command, let me
know.

If you just wish to print a report and allow the user to select the
printer, try:

DoCmd.SelectObject acReport, "ReportName", True
DoCmd.RunCommand acCmdPrint

ReportName must be within quotes unless you have first declared it as
a string and given it a Value:
Dim ReportName as String
ReportName = "Name of the report"
 
D

Dirk Goldgar

fredg said:
If you just wish to print a report and allow the user to select the
printer, try:

DoCmd.SelectObject acReport, "ReportName", True
DoCmd.RunCommand acCmdPrint


Won't that display the database window, if one has hidden it? I would
consider that a drawback.
 

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