I have a routine that will export a report to PDF and automatically create an outlook message with the pdf attached. When creating this, The players in this game were Access 2010 (where the routine and reports are contained)and Outlook 2010. I had all the necessary references selected. It works perfectly. UNTIL I GOT IT TO THE CLIENT. The majority of the users use the above software. However, there are a number of users that use Office and Outlook 2007 (EVERY ONE USES ACCESS 2010). How can I incorporate code VBA code to allow users to use Outlook 2007 and 2010. The code, I may have an idea, just check for version and use the appropiate code for the particular version you use. I am just not sure how. One other thing, how do I allow for multiple references? As it stands now, I have references for Outlook 2010. I imagine I need to isntall Outlook 2007 to allow for those users. However, if include the reference for both Outlook versions, would my users not get error messages when they open the application and not have the appropriate reference selected if they do not have the reference availible?
Here is the code for Outlook 2010
++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++
Function sndCurRpt()
Rem !-- Make sure the Microsoft Object xx.0 Reference Library is enabled & _
(found under ToolsReferences in the VBA Editor) --
Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem
Dim strAttach1 As String
Dim PdfRep As String
Dim Currept As String
Dim CurreptCap As String
'Current Report Name
Currept = Screen.ActiveReport.Name
CurreptCap = Screen.ActiveReport.Caption
Set objOutlook = CreateObject("Outlook.Application.14")
Set objEmail = objOutlook.CreateItem(olMailItem)
' Check for PDF Repository
PdfRep = "c:\pdfrep\"
If Dir(PdfRep, vbDirectory) = "" Then MkDir PdfRep
'Output Reports
Rem !-- change Reportx to match the report names you wish to export. & _
IMPORTANT Make sure the location you select to save your reports to exists, Access will & _
not create the folders for you. --
'DoCmd.Close acReport, Screen.ActiveReport.Name
DoCmd.OutputTo acOutputReport, Currept, acFormatPDF, PdfRep & CurreptCap & ".pdf", False
'DoCmd.OutputTo acOutputReport, Report1, acFormatRTF, CYourFolderReport1.RTF, False
'DoCmd.OutputTo acOutputReport, Report2, acFormatRTF, CYourFolderReport1.RTF, False
'DoCmd.OutputTo acOutputReport, Report3, acFormatRTF, CYourFolderReport1.RTF, False
'DoCmd.OutputTo acOutputReport, Report4, acFormatRTF, CYourFolderReport1.RTF, False
'DoCmd.OutputTo acOutputReport, Report5, acFormatRTF, CYourFolderReport1.RTF, False
'Set Attachments
Rem !-- make sure to correlate the attachments to each of the reports you wish to send --
strAttach1 = PdfRep & CurreptCap & ".pdf"
'strAttach2 = CYourFolderReport2.RTF
'strAttach3 = CYourFolderReport3.RTF
'strAttach4 = CYourFolderReport4.RTF
'strAttach5 = CYourFolderReport5.RTF
'Generate email
With objEmail
.To = "email@removed.com"
'.Subject = "Your subject here"
.Subject = Screen.ActiveReport.Caption
.Body = "Attached Reports"
.Display
.Attachments.Add strAttach1
'.Attachments.Add strAttach2
'.Attachments.Add strAttach3
'.Attachments.Add strAttach4
'.Attachments.Add strAttach5
End With
'Remove attachments from drive
Kill strAttach1
'Kill strAttach2
'Kill strAttach3
'Kill strAttach4
'Kill strAttach5
End Function