Automating Outlook from within 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
 
Ad

Advertisements

J

JP

Check out the ".SentOnBehalfOfName" property -- you can use it to
specify a sender


HTH,
JP
 
G

Guest

Thank you...

I was trying to find this property without success. Would it be possibe for
you to supply me with simple syntax for its use.

Thanks
Fred Alyea
 
J

JP

It's a property of the MailItem so you would need to include it in the
appropriate With statement. I added it into your code below. Note that
the "send on behalf of" option only works if you are set up with the
authority to send emails on behalf of someone else. If you aren't set
up as a delegate for that user/mailbox, the email may not be sent.


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

.SentOnBehalfOfName = "(e-mail address removed)"

' 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



HTH,
JP
 
J

JP

ps Fred - if you click on a blank line in your code inside the "With
objOutlookMsg" statement, type a "." (period) and you should get an
Intellisense dropdown list of the properties available for the
MailItem. You can simply select one and then hit F1 to get help on
what it does.


HTH,
JP
 
Ad

Advertisements

G

Guest

Thanks JP... this is just what im looking for. Appreciate the updated code,
was thinking that was the way that property worked but was not sure. This
adds the needed functionally to the application I have written.

Fred Alyea
 
Ad

Advertisements


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