Accessdatabase print report to PDF via command button

I have an access database. I have a form with command buttons to print a report. When I click on the command button I am prompted for "CoID". CoID is an auto number. After I enter the CoID number my report prints. Is there a way to print the report to PDF vs. printing on my printer? Or can I get the option to print or PDF?

Thank you.

Conernesto
ConernestoAsked:
Who is Participating?
 
ConernestoAuthor Commented:
Hi,

I crated a simple database with a table named Table1_tbl. I also created a form and report. The Form name is Table1_frm and the Report name is Table1_rpt. Please open Table1_frm and click on the command button named Print Report (on the button of the form. I now have the option of printing to PDF or my regular printer. It seems that the default is PDF which is what I wanted. Attached is the simple database. To get the option to print to PDF, I added the command button.

So I think we are done with this one.
Blank1-12-9-2015.accdb
0
 
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
CoID is an auto number.

 Something in the report (a control, sort and group option, etc) or query that the report is based on, is referring to ColD

  It's also possible that it's simply mis-spelled.....should it not be ColID rather than ColD?

  If the report is based on a query, trying opening the query on it's own.  If your not prompted, then the problem is in the report.   If it truly needs ColD, then add it to the query.

Is there a way to print the report to PDF vs. printing on my printer? Or can I get the option to print or PDF?

 When you open the report, specify PDF:

                DoCmd.OutputTo acOutputReport, "rptMyReport", acFormatPDF, strFileName

 and give a file name.

Jim.
0
 
ConernestoAuthor Commented:
Hi,

I believe the command button has below. How would I change the code to print PDF?

Private Sub EFT_Approval_Form_Click()
On Error GoTo Err_EFT_Approval_Form_Click

    Dim stDocName As String

    stDocName = "EFT by CoID Rev_rpt"
    DoCmd.OpenReport stDocName, acNormal

Exit_EFT_Approval_Form_Click:
    Exit Sub

Err_EFT_Approval_Form_Click:
    MsgBox Err.Description
    Resume Exit_EFT_Approval_Form_Click
End Sub
0
Network Scalability - Handle Complex Environments

Monitor your entire network from a single platform. Free 30 Day Trial Now!

 
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
DoCmd.OutputTo acOutputReport, "EFT by CoID Rev_rpt", acFormatPDF, "EFTbyCoIDRev_rpt.PDF"

 in place of:

    stDocName = "EFT by CoID Rev_rpt"
    DoCmd.OpenReport stDocName, acNormal

Jim.
0
 
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
Sorry, needs to be this:

                stDocName = "EFT by CoID Rev_rpt"
                DoCmd.OpenReport stDocName, ", acViewPreview, , , acHidden

                DoCmd.OutputTo acOutputReport, stDocName, acFormatPDF,  "EFTbyCoIDRev_rpt.PDF"

                'close the report
                DoCmd.Close acReport, stDocName
0
 
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
Are you all set then?

Jim.
0
 
ConernestoAuthor Commented:
It worked.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.