Avatar of Fordraiders
Fordraiders
Flag for United States of America

asked on 

open outlook and run a function from Access

Outlook 2010
Access 2010

I need to open Outlook from MsAccess. Then run a function and then close outlook  ?

Sub Run Function()
    On Error Resume Next
    Dim OutApp As Object
    Dim OutMail As Object
    Dim objNsp As Object
    Dim colSyc As Object
    Dim objSyc As Object
    Dim i As Integer

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
    Set objNsp = OutApp.Application.GetNamespace("MAPI")  'CORRECTION to Refer to the OutLook Application correctly
    Set colSyc = objNsp.SyncObjects

    On Error Resume Next
    With OutMail
        .To = "whatever@whatever.com"
        .Subject = "Vetting Report - " & TBFileName.Text
        .Body = "For Your Information .."
        .Attachments.Add BFld1 & TBFileName.Text
        .Send ' to send in background
        ' .Display ' to open a mail window with a normal 'SEND' icon available
    End With

    For i = 1 To colSyc.Count
        Set objSyc = colSyc.Item(i)
        objSyc.Start
    Next

    On Error GoTo 0

    OutApp.Quit

    Set OutMail = Nothing
    Set objNsp = Nothing
    Set colSyc = Nothing
    Set objSyc = Nothing
    Set OutApp = Nothing

aa:
End Sub

Open in new window



The code above is just to open Outlook and send an email.
I need it to run a function in Outlook ?


Thanks
fordraiders
Microsoft AccessOutlook

Avatar of undefined
Last Comment
crystal (strive4peace) - Microsoft MVP, Access

8/22/2022 - Mon