I would like users to print, using a print button shown on my forms. I
already have the buttons created and properly labeled, and I have reports
already made for each of my forms. What VBA code do I enter in order to make
a print button actually print the report? Thanks.
Hi Dino,
Do you mean something like the following?
stDocName = "some_report"
DoCmd.OpenReport stDocName, acNormal
Then you just copy this code for each button and change out the report name
> I would like users to print, using a print button shown on my forms. I
> already have the buttons created and properly labeled, and I have reports
> already made for each of my forms. What VBA code do I enter in order to make
> a print button actually print the report? Thanks.
Hi Dino,
some further info, for me, Access autogenerates this code when I create the
button.
I'm including it all because my previous sample didn't include an error
handler or the declaration...which was bad on my part
On Error GoTo Err_Command5_Click
Dim stDocName As String
stDocName = "tblEmployer"
DoCmd.OpenReport stDocName, acNormal
Exit_Command5_Click:
Exit Sub
Err_Command5_Click:
MsgBox Err.Description
Resume Exit_Command5_Click
> I would like users to print, using a print button shown on my forms. I
> already have the buttons created and properly labeled, and I have reports
> already made for each of my forms. What VBA code do I enter in order to make
> a print button actually print the report? Thanks.
Dino - 25 Apr 2006 23:51 GMT
Thanks Denny,
I tried the code from your first reply and it worked great. I will use the
additional code from this reply. One thing though, and this may be outside
the realm of Access, and more about the setup in my office:
When I click on the print button, it automatically starts printing to my
default printer in the office, without giving me the usual menu such as which
printer I want to print to, color vs. greyscale, etc. Is that something I
will just have to deal with?
Dino
> Hi Dino,
>
[quoted text clipped - 21 lines]
> > already made for each of my forms. What VBA code do I enter in order to make
> > a print button actually print the report? Thanks.
Denny - 26 Apr 2006 16:33 GMT
Hi Dino.
To preview the report first use this command:
DoCmd.OpenReport stDocName, acPreview
Notice the only difference here is the acPreview.
hope that helps.
> Thanks Denny,
> I tried the code from your first reply and it worked great. I will use the
[quoted text clipped - 33 lines]
> > > already made for each of my forms. What VBA code do I enter in order to make
> > > a print button actually print the report? Thanks.
Dino - 26 Apr 2006 22:07 GMT
Thanks Denny, it worked great!
> Hi Dino.
>
[quoted text clipped - 41 lines]
> > > > already made for each of my forms. What VBA code do I enter in order to make
> > > > a print button actually print the report? Thanks.
Serogen - 18 Nov 2008 14:59 GMT
This is exactly what I need. My only questions now (as stupid as it may
be)...WHERE do you enter these codes? I'm thinking Macro, "Action" and
"Argument", but that doesn't seem right. Does it go in the Visual Basic
window? fyi...I'm using Office 2007.
> Hi Dino.
>
[quoted text clipped - 41 lines]
> > > > already made for each of my forms. What VBA code do I enter in order to make
> > > > a print button actually print the report? Thanks.