I have an Access database that will send an email when the user clicks a command button. The functionality worked fine on one computer yesterday but is not working on another today.
The error occurs on the following code:
Set objOutlook = CreateObject("Outlook.Appl
ication")
I have the following references set:
Visual Basic for Applications
Microsoft Access 9.0 Object Library
OLE Automation
Microsoft Outlook 11.0 Object Library
Microsoft DAO 3.6 Object Library
The full code for the email function that is failing is:
Public Sub NotifyEmail(strEMailRecipi
ent, strReport, strSubject, strBody)
'This function will send an email with a report
'attachment when a user elects.
'Dim objOutlook As Outlook.Application
'Dim objOutlookMsg As Outlook.MailItem
'Set objOutlookMsg = objOutlook.CreateItem(olMa
ilItem)
Dim objOutlook As Object
Dim objOutlookMsg As Object
Dim strCurrentUser As String
Set objOutlook = CreateObject("Outlook.Appl
ication")
Set objOutlookMsg = objOutlook.CreateItem(0)
strCurrentUser = CurrentUser()
On Error GoTo CancelEmail
DoCmd.SendObject objecttype:=acSendReport, _
objectname:=strReport, _
outputformat:=acFormatRTF,
_
To:=strEMailRecipient, _
Subject:=strSubject, _
messagetext:=strBody
Exit_Here:
Set objOutlook = Nothing
Exit Sub
Error_Handler:
MsgBox Err & ": " & Err.Description
Resume Exit_Here
GoTo ErrorHandler
CancelEmail:
' MsgBox "The transaction was cancelled. "
MsgBox "Error #" & Err.Number & ": " & Err.Description & " by " & Err.Source, vbOKOnly, "Error in procedure Form_Open of frmSelectUsers"
CancelEmailExit:
Exit Sub
ErrorHandler:
MsgBox "The report was emailed to " & strEMailRecipient & " successfully ."
ErrorHandlerExit:
Exit Sub
End Sub
Start Free Trial