Sending massive emails from Access to Outlook may be very annoying because the protection configuration of Outlook itself. Disabling protection  will not be helpful (you can do it running the executable as Administrator). The technique I prefer is explained here:

1) Into the module declarations insert this:

Dim namespaceOutlook As Outlook.NameSpace
2) in the module itself let's create a sub:
Sub modOutlook_OpenOutlook()
    ' Initialize outlook objects
    On Error Resume Next
    Set appOutlook = GetObject(, "Outlook.Application")
    If Err <> 0 Then
        ' attempt to start outlook
        ' Note that this code can be used to start a second instance of outlook
        Set appOutlook = New Outlook.Application
        Set namespaceOutlook = appOutlook.GetNamespace("MAPI")
        Dim folderOutlook As Folder
        Set folderOutlook = namespaceOutlook.GetDefaultFolder(olFolderInbox)
        ' make outlook visible on the desktop
        folderOutlook.Display
    Else
        Set namespaceOutlook = appOutlook.GetNamespace("MAPI")
    End If
End Sub

3) let's create, into the same module, this sub:
Sub modOutlook_Tidy()
Set namespaceOutlook = Nothing
Set appOutlook = Nothing
End Sub

4) Now let's create the main function. We have to pass to the function the variables we need to make it work (variables are commented into the code):
Sub modOutlook_SendMail(ByVal docPDF As String, ByVal oggetto As String, ByVal destinatario As String, ByVal msg As String)
modOutlook_OpenOutlook
Dim mailOutlook As Outlook.MailItem
Set mailOutlook = appOutlook.CreateItem(olMailItem)
With mailOutlook
' please comment if not needed
.Subject = oggetto ' this is the Subject
.To = destinatario ' this is the recipient's email address
.Body = msg 'this is the message
.Attachments.Add docPDF 'this is the Attachment (here is a PDF but you can attach everything)
'.Display ' comment out if you need to display the message you're sending
.Send
End With
Set mailOutlook = Nothing
modOutlook_Tidy
End Sub

Using this kind of programming (OOP) we operate from the inside of Access like we do insode Outlook. For this reason no one annoying security alert message will bring.



Leave a Reply.