Email from Access 2007 & and set [from] in VB code

jlcford

New member
Local time
Today, 13:41
Joined
Nov 11, 2008
Messages
8
Is there anyway to change to a group mailbox from the default mailbox when using Microsoft Exchange Server to send batch emails from Access 2007 using VB code. I can't find a reference to [From] that works anywhere in a line of code like below:


DoCmd.SendObject acSendReport, "MyReportName", acFormatPDF, [To], [Cc], [Bc], [Subject],[MessageText],[EditMessage],[TemplateFile]


Thanks,

jlcford
 
Sendobject is a vba method with limited functionality. Therefore you need to consider sending emails using the Outlook object model. Full reference here.

This using the Outlook object model gives you the SentOnBehalfOfName property where you can set the sender.

If you are unfamiliar with objects then what you do is create an object (in this case an outlook email), then set the various properties for that object, then send it.

Some code like (untested):

Code:
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim ObjOutlookRecip As Outlook.Recipient

Set objOutlook = CreateObject("Outlook.Application")
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

With objOutlookMsg
   Set ObjOutlookRecip = .Recipients.Add("bill.gates@microsft.com")
   ObjOutlookRecip.Type = olTo
   .Subject = "my email subject"
   .SentOnBehalfOfName = "mySenderAccount"
   .Body = "message body"
   .send
End With


The object model can be used to control many aspects of an email, not just the ones here.

hth
Chris
 
Last edited:
Thanks

jlcford
 

Users who are viewing this thread

Back
Top Bottom