Solved

How do I create an event procedure to save to a PDF file?

Posted on 2013-12-12
2
647 Views
Last Modified: 2013-12-12
I would like to create a button on my form to save a file as PDF.  Below I have code that enables me to create the focus on the current record then open it in print preview.  I would like to have the report open as a PDF.  When I create a button, I can create a macro, but need it to focus on the current record.  How do I do this?  


Private Sub print_Click()
    Dim strWhere As String
   
    If Me.Dirty Then    'Save any edits.
        Me.Dirty = False
    End If

    If Me.NewRecord Then 'Check there is a record to print
        MsgBox "Select a record to print"
    Else
        strWhere = "[ID] = " & Me.[ID]
        DoCmd.OpenReport "Daily Job Summary", acViewPreview, , strWhere
    End If
End Sub


Thank you for your help :)
0
Comment
Question by:becrosby
2 Comments
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
ID: 39715375
you can use this command to create a PDF file from your report


DoCmd.OutputTo acOutputReport, "Daily Job Summary", acFormatPDF


create another command button cmdCreatePDF

change "NAMEOFTABLE" below with the actual name of your table or query

Private Sub cmdCreatePDF_Click()
    Dim strWhere As String
   
    If Me.Dirty Then    'Save any edits.
        Me.Dirty = False
    End If

    If Me.NewRecord Then 'Check there is a record to print
        MsgBox "Select a record to print"
    Else
        strWhere = "[ID] = " & Me.[ID]
      DoCmd.OpenReport "Daily Job Summary", acViewDesign, , , acHidden
      Reports![Daily Job Summary].RecordSource = "Select * from NAMEOFTABLE Where " & strWhere
      DoCmd.Close acReport, "Daily Job Summary", acSaveYes
      DoCmd.OutputTo acOutputReport, "Daily Job Summary", acFormatPDF

    End If
End Sub
0
 

Author Closing Comment

by:becrosby
ID: 39715401
Thank you!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
The canonical version of this article is on my web site here: http://iconoun.com/articles/collisions/ A companion presentation is available here: http://iconoun.com/articles/collisions/Unicode_Presentation.pdf
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now