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
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