Solved

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

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

Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

615 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