Results 1 to 2 of 2
  1. #1
    Tomlon is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2012
    Posts
    7

    PDF Creation and Emailing via Outlook

    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

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    You use late binding. You can Google it, but the essential differences (my code, so replace with your variables):

    Code:
    Dim objOutlook         As Object
    Dim objMailItem        As Object
    
    Set objOutlook = CreateObject("Outlook.Application")
    Set objMailItem = objOutlook.CreateItem(0)
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 11
    Last Post: 05-20-2014, 11:32 AM
  2. Emailing example
    By pkstormy in forum Code Repository
    Replies: 4
    Last Post: 01-31-2014, 04:22 PM
  3. Emailing
    By fastebs in forum Access
    Replies: 2
    Last Post: 04-13-2012, 12:37 AM
  4. Replies: 3
    Last Post: 12-05-2011, 02:19 PM
  5. Assigning Outlook task from shared Outlook mailbox
    By Remster in forum Programming
    Replies: 2
    Last Post: 11-16-2011, 04:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums