Is there a way to programmatically print only a single page of a R

  • Thread starter Thread starter ThriftyFinanceGirl
  • Start date Start date
T

ThriftyFinanceGirl

I would like to give my users a button that will print the summary page of a
report quickly (first Page only). Is there a way to programmatically print
only the first page of a report, transparently to the user?

I have seen the Docmd.PrintOut, however, I think that is only for forms and
datasheets...
 
ThriftyFinanceGirl said:
I would like to give my users a button that will print the summary page of
a
report quickly (first Page only). Is there a way to programmatically
print
only the first page of a report, transparently to the user?

I have seen the Docmd.PrintOut, however, I think that is only for forms
and
datasheets...


The help file does imply that, but it's wrong. Bear in mind, though, that
it will print out the active object, so you have to ensure that your report
is the active object.
 
Hmmmm... that will be tricky since I would open the report through a
procedure on a form.... any suggestions on that?
 
ThriftyFinanceGirl said:
Hmmmm... that will be tricky since I would open the report through a
procedure on a form.... any suggestions on that?


You can do this:

DoCmd.OpenReport "YourReport", acViewPreview
DoCmd.PrintOut acPages, 1, 1
DoCmd.Close acReport, "YourReport", acSaveNo

That will show the report to the user momentarily, though, just long enough
to send it to the printer. If you don't want the user to see the report at
all, it will be a lot trickier.
 
I would like to give my users a button that will print the summary page of a
report quickly (first Page only). Is there a way to programmatically print
only the first page of a report, transparently to the user?

I have seen the Docmd.PrintOut, however, I think that is only for forms and
datasheets...

You are not correct regarding DoCmd.PrintOut.
It prints out whatever the active object is, so, if you have a command
button on your form and you wish to print out a report you must first
select the report, otherwise, by itself, you will print the form
because the form is the active object.

Just the first page?
The report is NOT open?

Code a command button on a form:

DoCmd.SelectObject acReport, "ReportName", True
DoCmd.PrintOut acPages, 1,1

If the Report is already open in Preview, change True to False.
 
That's what I was thinking. I think that I will just let them see a flash of
the report and be done with it! Sometimes you don't need to go overboard on
the programming! Thanks!
 
fredg said:
Just the first page?
The report is NOT open?

Code a command button on a form:

DoCmd.SelectObject acReport, "ReportName", True
DoCmd.PrintOut acPages, 1,1


The only problem with this, Fred, is that it will display the database
window/nav pane, even if the user has hidden it.
 
Wouldn't using the Echo method work, something like:

Public Sub EchoTest()

On Error GoTo ProcError

Application.Echo False
DoCmd.OpenReport "rptYourReport", acPreview
DoCmd.PrintOut acPages, 1, 1
DoCmd.Close acReport, "rptYourReport"

ProcExit:
Application.Echo True
Exit Sub
ProcError:
MsgBox Err.Number, Err.Description
Resume ProcExit

End Sub
 
Dale Fye said:
Wouldn't using the Echo method work, something like:

Public Sub EchoTest()

On Error GoTo ProcError

Application.Echo False
DoCmd.OpenReport "rptYourReport", acPreview
DoCmd.PrintOut acPages, 1, 1
DoCmd.Close acReport, "rptYourReport"

ProcExit:
Application.Echo True
Exit Sub
ProcError:
MsgBox Err.Number, Err.Description
Resume ProcExit

End Sub


I forgot all about that, Dale! I believe it would. The user would still
see the "Printing ..." dialog, but not the report's print-preview window.
Good thinking!

The MsgBox in your error-handler isn't quite right. You may want this
instead:

MsgBox Err.Description, vbExclamation, "Error " & Err.Number
 
Yep, that's what I was going to try...We'll see if it still recognizes the
focus even with the echo turned off. Great minds think alike!
 
ThriftyFinanceGirl said:
Yep, that's what I was going to try...We'll see if it still recognizes the
focus even with the echo turned off.

It worked in my test.
 
Glad I could help.

My only caution with using the Echo method is that you must ensure you have
an error handler and an exit proceedure so that even if you get an error
(what happens if your printer is offline, or you have a network connection
problem when trying to print), that you will get to the line that reads

Application.Echo True

If that line gets bypassed, you will not see any screen changes.
 
I have that option unchecked but as Dirk said, when you choose to force the
selection of the object, the database window does pop up. The other
suggestion works fine for me! Thanks everyone!
 
Back
Top