I have created the code below to send e-mail using late binding
Outlook Automation.
I have three questions though...
Can I send an Access report without haveing to output and save it as a
file as I can do using docmd.sendobject
How can I get Outlook to send the message automatically if it's not
open instead of having the mail sit in the outbox?
Is this code sound?
Thanks,
lq
Function SendOutlookMail(strEmailTo As String, _
strSubject As String, _
strMsgTxt As String, _
Optional strEmailCC As String, _
Optional strEmailBCC As String, _
Optional strAttachmentPath As String, _
Optional booDisplayMsg As Boolean = False)
Dim objOutlook As Object, _
objOutlookMsg As Object, _
objOutlookRecip As Object, _
objOutlookAttach As Object
'create the Outlook session:
Set objOutlook = CreateObject("Outlook.Application")
'create the message object:
Set objOutlookMsg = objOutlook.CreateItem(0)
With objOutlookMsg
'add the recipients:
Set objOutlookRecip = .Recipients.Add(strEmailTo)
objOutlookRecip.Type = 1 'olTo
'add the cc recipients:
If Not IsMissing(strEmailCC) Then
Set objOutlookRecip = .Recipients.Add(strEmailCC)
objOutlookRecip.Type = 2 'olCC
End If
'add the bcc recipients:
If Not IsMissing(strEmailBCC) Then
Set objOutlookRecip = .Recipients.Add(strEmailBCC)
objOutlookRecip.Type = 3 'olBCC
End If
.Subject = strSubject
.Body = strMsgTxt & vbCrLf
.Importance = 2 '>high importance
'add attachment:
If Not Isblank(strAttachmentPath) Then
Set objOutlookAttach = .Attachments.Add(strAttachmentPath)
End If
'resolve each recipient name:
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
Next
If booDisplayMsg Then
.Display
Else
.Send
End If
End With
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
End Function