Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2013-12-12
2
Medium Priority
?
687 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 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

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

715 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