Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert Access report to PDF send via Outlook 1

Status
Not open for further replies.

debq

Technical User
Aug 7, 2008
50
US
I am using the code below to convert multiple reports from Access into Word Doc and then send to various recipients via Outlook email.The code works great but the rtf format loses graphics and colors. I would like to convert to PDF instead. How can I change this code to convert to PDF and then send the PDF report as an attachment via Outlook?

CODE:
Option Compare Database
Option Explicit

Private Sub cmdConvertCombineAndEmail_Click()
On Error GoTo ERRORHANDLER
Dim varItem As Variant
If lstReports.ItemsSelected.Count > 0 Then
Dim AppWord As New Word.Application
Dim DocWrd As Word.Document
Dim i As Integer
Dim Progress As String
Dim EventTitle As String
AppWord.Visible = True
Set DocWrd = AppWord.Documents.Add
DocWrd.PageSetup.TopMargin = 36
DocWrd.PageSetup.BottomMargin = 36
DocWrd.PageSetup.LeftMargin = 36
DocWrd.PageSetup.RightMargin = 18
i = 0

EventTitle = "Mystery Caller Report"

For Each varItem In lstReports.ItemsSelected
i = i + 1
Progress = "Processing... " & lstReports.ItemData(varItem)
DoCmd.OutputTo acOutputReport, lstReports.Column(0, varItem), acFormatRTF, "c:\temp\" & lstReports.ItemData(varItem) & ".rtf", False
AppWord.Selection.InsertFile "c:\temp\" & lstReports.ItemData(varItem) & ".rtf", "", False, False, False
If i < lstReports.ItemsSelected.Count Then
AppWord.Selection.InsertBreak wdSectionBreakNextPage
End If
Next
Progress = "Generating Email"
DocWrd.SaveAs "c:\temp\" & EventTitle & ".doc", wdFormatDocument
DocWrd.BuiltInDocumentProperties("Title").Value = "Set the title of the combined reports - " & Date
DocWrd.Save
AppWord.Activate
AppWord.Options.SendMailAttach = True
DocWrd.SendMail
DocWrd.Close
Set DocWrd = Nothing
'Word Instance stays open??
'AppWord.Quit
Set AppWord = Nothing
End If

Progress = ""
Exit Sub

ERRORHANDLER:
Progress = ""
If MsgBox("Do you want to start over?", vbCritical + vbYesNo) = vbYes Then
Err.Clear
DocWrd.Close wdDoNotSaveChanges
AppWord.Quit
Exit Sub
Else
Err.Clear
Resume
End If

End Sub

Private Sub Form_Open(Cancel As Integer)
Dim lngRow As Long

If lstReports.MultiSelect Then
For lngRow = 0 To lstReports.ListCount - 1
lstReports.Selected(lngRow) = True
Next
End If

End Sub
 
Thank You Thank You Thank you. This works and has saved me in a big way. I do not have MS 2003 at work and cannot install outside programs without permission from IT. BUT I do have my personal Laptop with MS 2007 installed. I added the Cute pdf and downloaded the pdf creator. This will work for me. I am still learning VBA so this is a great help.

Thanks again
 
I phrased that badly. Access 2007 has its own built-in PDF routines. However, you may still find CutePDF useful.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top