Access VBA Macro Programming

(Joao Candeias) #1

Dim MoOutlook As Outlook.NameSpace
Set MoOutlook = oOutlook.GetNamespace("MAPI")
Set oFolder = MoOutlook.GetDefaultFolder(olFolderOutbox)
Set oItem = oFolder.Items.Add(olMailItem)
With oItem
.Recipients.Add ("[email protected]")
.Subject = "Test Access Email"
.Body = "This is a test of an email from Access VBA"
.Importance = olImportanceHigh
.Send
End With
Set oItem = Nothing
Set oFolder = Nothing
End Sub


When this code is run, you will get a pop-up dialog box warning that e-mail address
information is being accessed in Outlook. This is to prevent e-mail viruses, which use exactly
the same code as this.


Chapter 17: Using Access to Interact with Other Office Programs 225


Figure 17-2 Selecting the Object Library file for Microsoft Outlook

Free download pdf