Hello Access-Programmers,
I can open Outlook one time when running the code below.
Subsequent attempts generate error 462 which I have captured and requested user action.
This method seems a bit sloppy.
Is it possible that, close Outlook and Set Outmail = Nothing, commands are needed before exiting the function?
Any ideas on how to reliably open Outlook repetitively (not simultaneously) from within Access?
I can open Outlook one time when running the code below.
Subsequent attempts generate error 462 which I have captured and requested user action.
This method seems a bit sloppy.
Code:
Function SendEmail()
On Error Resume Next
Set OutApp = GetObject(, "Outlook.Application") ' See if outlook is open
If OutApp Is Nothing Then ' Open Outlook if not already Open
Set OutApp = CreateObject("Outlook.Application") ' Create new instance of Outlook
End If
On Error GoTo SendEmail_Err
Set OutMail = OutApp.CreateItem(olMailItem)
With OutMail ' Loads variables into proper sections of Outlook new email
.To = varAddress
.CC = varCC
.BCC = varBCC
.Subject = varSubject
.Body = varBody
.Importance = olImportanceNormal
.Display ' Brings Outlook new mail window into view (Deactivate for Auto Send)
' .send ' Activate to Auto Send
End With
SendEmail_Exit:
Exit Function
SendEmail_Err:
If Err.Number = 462 Then
MsgBox "Outlook can not be started remotely now." & Chr$(13) & _
"Please start Outlook manually and retry sending your Email.", vbOKOnly, _
"Outlook remote start failure"
Resume SendEmail_Exit
End If
MsgBox "Public Function: SendEmail" & Chr$(13) & _
"Error number: " & Err.Number & Chr$(13) & _
Err.Description, vbOKOnly, "mdlPublicFunctions"
Resume SendEmail_Exit
End Function
Is it possible that, close Outlook and Set Outmail = Nothing, commands are needed before exiting the function?
Any ideas on how to reliably open Outlook repetitively (not simultaneously) from within Access?
Last edited: