I have this VBA code use to send emails in my Access Database, and I also Referenced the Microsoft Outlook 14.0 Object Library.
Everything works perfectly when I run the code manually. However, Access fails when I run the Macro from Windows Task Schedular. I get this message:
Runtime error '429' ActiveX component can't create object
In the Actions tab in Task Scheduler I am referencing the Macro like this: "C:\Program Files\Microsoft Office\Office14\MSACCESS.EXE" "C:\mydata\Database\mydatabase.accdb" /X RunMyMacro
The error seem to be pointing to this code as indicated in the screenshot below.
Code:
Dim strEmailBody As String
Sub emailNotification()
Dim oFolder As Outlook.MAPIFolder
Dim oItem As Outlook.MailItem
Dim oOutlook As New Outlook.Application
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 = "my notification"
.Body = strEmailBody
.Importance = olImportanceHigh
.Send
End With
Set oFolder = Nothing
End Sub
Screenshot:

"C:\Program Files\Microsoft Office\Office14\MSACCESS.EXE" "C:\mydata\Database\mydatabase.accdb" /X RunMyMacroin the command line? - HelloW