Solved

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

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
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…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
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…

752 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