Solved

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

Posted on 2013-12-12
2
670 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This very simple solution applies to a narrow cross-section of the "needs to close" variety. In this case, the full message in Event Viewer was in applog, Event ID 1000: Faulting application iexplore.exe, version 8.0.6001.18702, faulting module …
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

920 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

16 Experts available now in Live!

Get 1:1 Help Now