I have been able to write a code that will send email via outlook. The next
improvement I would like to do is to select the account for outgoing email.
On my outlook I have 2 email accounts. (My personal account which is the
default. Another account is the shared account and it is the one I want my
VBA code using it.)
I found that there is a function Sendusingaccount and don't know how to use
it.
I would appreciate your help.
thanks so much,
Boon
Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples: http://www.devhut.net
Please rate this post using the vote buttons if it was helpful.
"Boon" wrote:
> .
>
I wrote the following code (no guarantees, I'm testing it out with a client
in Singapore right now).
The top portion tries to match the outlook account (I think I found a code
example on microsoft's site somewhere).
HTH,
Mark Andrews
RPT Software
http://www.rptsoftware.com
http://www.donationmanagementsoftware.com
Public Sub CreateEmail(strFrom As String, strTo As String, strCC As String,
strBCC As String, strSubject As String, strTextOrHTML As String, strBodyText
As String, strBodyHTML As String)
On Error GoTo Err_CreateEmail
Dim OlApp As Outlook.Application
Dim olAccounts As Outlook.Accounts
Dim olAccount As Outlook.Account
Dim olAccountTemp As Outlook.Account
Dim olMail As MailItem
Dim FoundAccount As Boolean
Set OlApp = New Outlook.Application
FoundAccount = False
'loop through and find Outlook account based on from email address
Set olAccounts = OlApp.Application.Session.Accounts
For Each olAccountTemp In olAccounts
If (olAccountTemp.smtpAddress = strFrom) Then
Set olAccount = olAccountTemp
FoundAccount = True
Exit For
End If
Next
If (FoundAccount) Then
Set olMail = OlApp.CreateItem(olMailItem)
With olMail
.SendUsingAccount = olAccount
.To = strTo
.CC = strCC
.BCC = strBCC
.Subject = strSubject
If (strTextOrHTML = "HTML") Then
.BodyFormat = olFormatHTML
.Body = strBodyText
.HTMLBody = strBodyHTML
Else
.BodyFormat = olFormatPlain
.Body = strBodyText
End If
' .Attachments.Add filename
.Display
End With
Else
MsgBox "Could not find the appropriate Outlook account for email
address: " & strFrom & ". Contact RPT Software for assistance if needed.",
vbOKOnly, "Outlook error retrieving SMTP account"
End If
Exit_CreateEmail:
Set olMail = Nothing
Set olAccount = Nothing
Set OlApp = Nothing
Exit Sub
Err_CreateEmail:
MsgBox Err.Description
Resume Exit_CreateEmail
End Sub
"Boon" <boonyawat....@cnh.com> wrote in message
news:uN4LI383...@TK2MSFTNGP04.phx.gbl...
"Mark Andrews" <mandrews__...@rptsoftware.com> wrote in message
news:Ojdw5J$3KHA...@TK2MSFTNGP06.phx.gbl...
"Mark Andrews" <mandrews__...@rptsoftware.com> wrote in message
news:Ojdw5J$3KHA...@TK2MSFTNGP06.phx.gbl...
'loop through available Outlook acoount and populate ComboFrom
Set OlApp = New Outlook.Application
For Each oAccount In OlApp.Session.Accounts
If oAccount.AccountType = olPop3 Then
Me.ComboFrom.AddItem oAccount.smtpAddress
End If
Next
If (Me.ComboFrom.ListCount < 1) Then
MsgBox "We cannot find any Outlook email accounts, so you cannot use
this email feature. Contact RPT Software for assistance if needed.",
vbOKOnly, "Error finding Outlook email account(s)"
DoCmd.Close
Else
Me.ComboFrom = Me.ComboFrom.ItemData(0)
End If
--
Mark Andrews
RPT Software
http://www.rptsoftware.com
http://www.donationmanagementsoftware.com
"Lee Taylor-Vaughan" <le...@CcOoMmCcAaSsTt.net> wrote in message
news:6D55EE62-91D8-477A...@microsoft.com...
Thanks Mark for your suggestion.
I am still stucked... It seems like the code you provided only select the
account type (exchange, live meeting,...)
In outlook2007, you can select the From Address. I can select the shared
email account to be sent from. For instance, my work email is
Bo...@company.com. The shared email address (the one I wish to send from) is
Share...@company.com. And says my personal email is Bo...@gmail.com.
From my outlook, when I send email, the default From Address is
Bo...@company.com. I can change the From address to Share...@company.com.
But I cannot change it to Bo...@gmail.com. This makes sense since the gmail
account is not on the company network..
Now, from Access, I would like to setup so that the email will be sent from
Share...@company.com.
The reason I would like to do this is that I don't want to use my company
email to send emails to several people. I don't want them to reply to my
work email. I want them to reply to the shared email and thus I think I need
to send it from Shared email account.
thanks for your help.
Boon
"Mark Andrews" <mandrews__...@rptsoftware.com> wrote in message
news:%23JFsuhK...@TK2MSFTNGP05.phx.gbl...
It is pretty simple. Just set the .SentOnBehalfOfName ="
Share...@company.com"
thanks!!
"Boon" <boonyawat....@cnh.com> wrote in message
news:OHnf$SM4KH...@TK2MSFTNGP04.phx.gbl...
"Boon" <boonyawat....@cnh.com> wrote in message
news:uU4bBVM4...@TK2MSFTNGP05.phx.gbl...
"Mark Andrews" <mandrews__...@rptsoftware.com> wrote in message
news:%23JFsuhK...@TK2MSFTNGP05.phx.gbl...