HillTJ
To train a dog, first know more than the dog..
- Local time
- Yesterday, 17:07
- Joined
- Apr 1, 2019
- Messages
- 731
Hi, I'm using the below code to open outlook from a command button on a popup form. All works well but outlook always opens minimized. I have another routine that uses the sendobject method (for different reason) and it works well. So what I do is check whether outlook is installed, if so use below code, but if outlook is not installed I use the sendobject method to open the default email browser (that may not be outlook).
Code:
Option Compare Database
Option Explicit
Public Function vcSendEmail_Outlook(sSubject As String, sTo As String, Optional sCC As String, Optional sBcc As String, Optional sAttachment As String, Optional sBody As String)
Dim OutApp As Object
Dim OutMail As Object
On Error GoTo ErrorHandler:
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)
OutMail.To = sTo
If sCC <> "" Then OutMail.CC = sCC
If sBcc <> "" Then OutMail.BCC = sBcc
OutMail.Subject = sSubject
OutMail.HTMLBody = sBody
If sAttachment <> "" Then
OutMail.Attachments.Add (sAttachment)
Else
End If
OutMail.Display 'Send | Display
Set OutMail = Nothing
ExitError:
Exit Function
ErrorHandler:
Select Case Err.Number
Case 440
MsgBox "Outlook Cancelled by User", vbOKCancel
Exit Function
Resume Next
Case 999
MsgBox "Error Description", vbOKCancel
Exit Function
Resume Next
Case Else
Call LogError(Err.Number, Err.Description, "Email Module")
Resume ExitError
End Select
End Function