Results 1 to 5 of 5
  1. #1
    sdel_nevo is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Location
    Gloucester, UK
    Posts
    402

    send an e-mail but with out requiring an refrence set

    Hi Guys



    i have this code that runs on the "On Click" event of a button

    Code:
    'This Command Opens the report in hidden mode so that the calculations work on the Report when it's output as a PDF
        DoCmd.OpenReport "rptCustomerStatement", acViewPreview, "", "", acHidden
    
    
        DoCmd.OutputTo acOutputReport, "rptCustomerStatement", acFormatPDF, (DLookup("FilePath", "tblCompanyDetails", "CompanyID = 1")) & "\customers" & "\" & Me.Full_Name & "\Statements" & "\" & (DLookup("[companyname]", "tblCompanyDetails", "CompanyID = 1")) & " Customer Statement" & " " & Format(Date, "dd-mm-yyyy") & ".pdf"  
    
    
        Dim OlApp                                              As Object
        Dim objMail                                            As Object
    
    
        On Error Resume Next    'Keep going if there is an error
        Set OlApp = GetObject(, "Outlook.Application")    'See if Outlook is open
        If Err Then    'Outlook is not open
            Set OlApp = CreateObject("Outlook.Application")    'Create a new instance of Outlook
        End If
    
    
        'Create e-mail item
        Set objMail = OlApp.CreateItem(olMailItem)
        With objMail
    
    
            'Set body format to HTML
            .BodyFormat = olFormatHTML
            .To = Me.E_Mail.Value
            .Subject = "Customer Statement Attached as of" & " " & Format(Date, "dddd d mmmm yyyy")
            .HTMLBody = "Dear" & " " & Me.Full_Name.Value & " " & Me.Email_Statement_text.Value
            .Attachments.Add (DLookup("FilePath", "tblCompanyDetails", "CompanyID = 1")) & "\customers" & "\" & Me.Full_Name & "\Statements" & "\" & (DLookup("[companyname]", "tblCompanyDetails", "CompanyID = 1")) & " Customer Statement" & " " & Format(Date, "dd-mm-yyyy") & ".pdf"   
            .Display
    
    
        End With
        Set OlApp = Nothing
        Set objMail = Nothing
        DoCmd.Close acReport, "rptCustomerStatement", acSaveYes
        Me.Sent_Date = Date
    This works really well and attaches the report to the e-mail as an attachment

    However, what i would really like to do is to change the code so that i do not need a reference adding to the "Tools - references" section of the VBA IDE

    I know their is early and late binding, im not sure which this uses and what i need to change
    we have different versions of outlook installed on some computers and i was looking for a better way of doing things

    once again
    many thanks

    Steve

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    This is how vb works.
    I had code to inspect the version of Outlook, then add itself to the REFERNECES.

  3. #3
    sdel_nevo is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Location
    Gloucester, UK
    Posts
    402
    Hi ranman256

    that's a good idea, can you remember how you did that
    steve

  4. #4
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    This is not the exact code but about what it did. To distribute the FE, you must remove any reference to outlook.
    Then when the user opens the app (in form load), it checks to see if the Ref exists, if not, it loads it.
    (I will try to find the working code)

    Code:
    Form_Load
      Check4Reference
    end sub
     
    sub Check4Reference()
       'if missing , add reference
    if References("Outlook") = "" then
    select case true
      case  DirExists("C:\Program Files (x86)\Microsoft Office\Office15")
     References.AddFromFile "C:\WINDOWS\system32\outlook15.dll"
      case  DirExists("C:\Program Files (x86)\Microsoft Office\Office14")
     References.AddFromFile "C:\WINDOWS\system32\outlook14.dll"
      case  DirExists("C:\Program Files (x86)\Microsoft Office\Office13")
     References.AddFromFile "C:\WINDOWS\system32\outlook13.dll"
    end select     
    endif
    end sub
     
    Public Function DirExists(ByVal pvDir) As Boolean
    Dim fso
    Set fso = CreateObject("Scripting.FileSystemObject")
    DirExists = fso.FolderExists(pvDir)
    Set fso = Nothing
    End Function

  5. #5
    sdel_nevo is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Location
    Gloucester, UK
    Posts
    402
    Hi, that's brill many thanks will see how I get on with this

    many many thanks
    steve

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

Similar Threads

  1. Send e-mail in ACCDE
    By Tom Hovens in forum Modules
    Replies: 0
    Last Post: 03-16-2015, 12:40 AM
  2. Send automatic e-mail
    By Csalge in forum Forms
    Replies: 1
    Last Post: 04-08-2013, 11:33 AM
  3. Replies: 1
    Last Post: 09-14-2012, 10:27 AM
  4. send a form via mail
    By Fabdav in forum Forms
    Replies: 1
    Last Post: 10-12-2011, 07:35 AM
  5. Send mail to the chosen ones
    By carstenhdk in forum Import/Export Data
    Replies: 0
    Last Post: 05-18-2010, 11:51 PM

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