Automating Outlook from inside Access

G

Guest

Im attempting to automate and Outlook Email send from within an Access
application. This is the code I'm using.

Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment

Dim mMgrAddy As String
Dim mEmpAddy As String

mBody = "This is test of the olOriginator MailItem"

' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")

' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

With objOutlookMsg
' Add the To recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add(mEmpAddy)
objOutlookRecip.Type = olTo

' Add the From recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add(mMgrAddy)
objOutlookRecip.Type = olBCC

' Set the Subject, Body, and Importance of the message.
.Subject = "This is a TEST Email"
.Body = mBody & vbCrLf & vbCrLf
.Importance = olImportanceHigh 'High importance

' Resolve each Recipient's name.
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
Next

' Should we display the message before sending?
If DisplayMsg Then
.Display
Else
.Save
.Send
End If
End With

My question has to do with the "From" button which opens Choose Sender when
working directly in Outlook. The person running the Access application has
rights to a specific email addy they can use but I cant seem to figure out
how to make the application use the "From" or Choose Sender Outlook feature.

Appreciate any assistance on this.

Thanks
Fred Alyea
 
G

GeoffG

The "olBCC" constant will designate recipients who are to receive blind
carbon copies. Recipients in the "To" field won't know that the BCC
recipients are getting copies.

You've used the olBCC constant to designate **From recipients**, which isn't
right. A recipient isn't a sender. I think you can only change the sender
in Outlook 2007, not earlier versions. This is because the object model for
earlier versions of Outlook don't have the necessary Sender property of the
MailItem object.

Suggest you repost to an Outlook newsgroup or search the Microsoft website.
I know I've seen something recently on the MS site.

Geoff
 
G

Guest

Thanks...

I posted there also. Discovered the MailItem .sentOnBehalfOfName which
works perfect for what I needed.


Fred Alyea
 
G

GeoffG

On re-reading, I'm not sure I read your original post correctly. My fault.

Interesting solution - thanks for posting back.

Geoff
 
A

Alt255

Im attempting to automate and Outlook Email send from within an Access
application. This is the code I'm using.

Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment

Dim mMgrAddy As String
Dim mEmpAddy As String

mBody = "This is test of the olOriginator MailItem"

' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")

' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

With objOutlookMsg
' Add the To recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add(mEmpAddy)
objOutlookRecip.Type = olTo

' Add the From recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add(mMgrAddy)
objOutlookRecip.Type = olBCC

' Set the Subject, Body, and Importance of the message.
.Subject = "This is a TEST Email"
.Body = mBody & vbCrLf & vbCrLf
.Importance = olImportanceHigh 'High importance

' Resolve each Recipient's name.
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
Next

' Should we display the message before sending?
If DisplayMsg Then
.Display
Else
.Save
.Send
End If
End With

My question has to do with the "From" button which opens Choose Sender when
working directly in Outlook. The person running the Access application has
rights to a specific email addy they can use but I cant seem to figure out
how to make the application use the "From" or Choose Sender Outlook feature.

Appreciate any assistance on this.

Thanks
Fred Alyea

I use this

mitem.SentOnBehalfOfName = rst1.Fields("Mailbox")

I have a query that get the name of the mailbox and my Outlook account
has the ability to send emails on their behalf.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top