From: Mark Andrews on 20 Apr 2010 12:42 Your second wish: Here's some code in the form_load event of my email form: '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" <leetv(a)CcOoMmCcAaSsTt.net> wrote in message news:6D55EE62-91D8-477A-AA1F-74E1A24E9A6B(a)microsoft.com... > one question. > How can i populate a combo box with the list of outlook SMTP accounts on a > form? > thanks > lee > > > > "Mark Andrews" <mandrews___NOSPAM___(a)rptsoftware.com> wrote in message > news:Ojdw5J$3KHA.1452(a)TK2MSFTNGP06.phx.gbl... >> Boon, >> >> 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.la-ongthong(a)cnh.com> wrote in message >> news:uN4LI383KHA.4336(a)TK2MSFTNGP04.phx.gbl... >>> Hello, >>> >>> 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 >>> >>> >
From: Boon on 20 Apr 2010 16:04 Hi, 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 Boon(a)company.com. The shared email address (the one I wish to send from) is SharedEmail(a)company.com. And says my personal email is Boon(a)gmail.com. From my outlook, when I send email, the default From Address is Boon(a)company.com. I can change the From address to SharedEmail(a)company.com. But I cannot change it to Boon(a)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 SharedEmail(a)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___NOSPAM___(a)rptsoftware.com> wrote in message news:%23JFsuhK4KHA.4964(a)TK2MSFTNGP05.phx.gbl... > Your second wish: > Here's some code in the form_load event of my email form: > > '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" <leetv(a)CcOoMmCcAaSsTt.net> wrote in message > news:6D55EE62-91D8-477A-AA1F-74E1A24E9A6B(a)microsoft.com... >> one question. >> How can i populate a combo box with the list of outlook SMTP accounts on >> a form? >> thanks >> lee >> >> >> >> "Mark Andrews" <mandrews___NOSPAM___(a)rptsoftware.com> wrote in message >> news:Ojdw5J$3KHA.1452(a)TK2MSFTNGP06.phx.gbl... >>> Boon, >>> >>> 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.la-ongthong(a)cnh.com> wrote in message >>> news:uN4LI383KHA.4336(a)TK2MSFTNGP04.phx.gbl... >>>> Hello, >>>> >>>> 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 >>>> >>>> >>
From: Boon on 20 Apr 2010 16:08 Minutes after I replied I found out the solution! It is pretty simple. Just set the .SentOnBehalfOfName =" SharedEmail(a)company.com" thanks!! "Boon" <boonyawat.la-ongthong(a)cnh.com> wrote in message news:OHnf$SM4KHA.1660(a)TK2MSFTNGP04.phx.gbl... > Hi, > > 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 > Boon(a)company.com. The shared email address (the one I wish to send from) > is SharedEmail(a)company.com. And says my personal email is Boon(a)gmail.com. > > From my outlook, when I send email, the default From Address is > Boon(a)company.com. I can change the From address to > SharedEmail(a)company.com. But I cannot change it to Boon(a)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 SharedEmail(a)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___NOSPAM___(a)rptsoftware.com> wrote in message > news:%23JFsuhK4KHA.4964(a)TK2MSFTNGP05.phx.gbl... >> Your second wish: >> Here's some code in the form_load event of my email form: >> >> '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" <leetv(a)CcOoMmCcAaSsTt.net> wrote in message >> news:6D55EE62-91D8-477A-AA1F-74E1A24E9A6B(a)microsoft.com... >>> one question. >>> How can i populate a combo box with the list of outlook SMTP accounts on >>> a form? >>> thanks >>> lee >>> >>> >>> >>> "Mark Andrews" <mandrews___NOSPAM___(a)rptsoftware.com> wrote in message >>> news:Ojdw5J$3KHA.1452(a)TK2MSFTNGP06.phx.gbl... >>>> Boon, >>>> >>>> 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.la-ongthong(a)cnh.com> wrote in message >>>> news:uN4LI383KHA.4336(a)TK2MSFTNGP04.phx.gbl... >>>>> Hello, >>>>> >>>>> 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 >>>>> >>>>> >>> > >
From: Mark Andrews on 20 Apr 2010 17:18 Glad you figured it out. Mark "Boon" <boonyawat.la-ongthong(a)cnh.com> wrote in message news:uU4bBVM4KHA.4016(a)TK2MSFTNGP05.phx.gbl... > Minutes after I replied I found out the solution! > > It is pretty simple. Just set the .SentOnBehalfOfName =" > SharedEmail(a)company.com" > > thanks!! > > "Boon" <boonyawat.la-ongthong(a)cnh.com> wrote in message > news:OHnf$SM4KHA.1660(a)TK2MSFTNGP04.phx.gbl... >> Hi, >> >> 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 >> Boon(a)company.com. The shared email address (the one I wish to send from) >> is SharedEmail(a)company.com. And says my personal email is Boon(a)gmail.com. >> >> From my outlook, when I send email, the default From Address is >> Boon(a)company.com. I can change the From address to >> SharedEmail(a)company.com. But I cannot change it to Boon(a)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 SharedEmail(a)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___NOSPAM___(a)rptsoftware.com> wrote in message >> news:%23JFsuhK4KHA.4964(a)TK2MSFTNGP05.phx.gbl... >>> Your second wish: >>> Here's some code in the form_load event of my email form: >>> >>> '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" <leetv(a)CcOoMmCcAaSsTt.net> wrote in message >>> news:6D55EE62-91D8-477A-AA1F-74E1A24E9A6B(a)microsoft.com... >>>> one question. >>>> How can i populate a combo box with the list of outlook SMTP accounts >>>> on a form? >>>> thanks >>>> lee >>>> >>>> >>>> >>>> "Mark Andrews" <mandrews___NOSPAM___(a)rptsoftware.com> wrote in message >>>> news:Ojdw5J$3KHA.1452(a)TK2MSFTNGP06.phx.gbl... >>>>> Boon, >>>>> >>>>> 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.la-ongthong(a)cnh.com> wrote in message >>>>> news:uN4LI383KHA.4336(a)TK2MSFTNGP04.phx.gbl... >>>>>> Hello, >>>>>> >>>>>> 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 >>>>>> >>>>>> >>>> >> >> > >
From: Lee Taylor-Vaughan on 23 Apr 2010 09:21 Mark, You ROCK! Thanks a ton.. works great! Lee "Mark Andrews" <mandrews___NOSPAM___(a)rptsoftware.com> wrote in message news:%23JFsuhK4KHA.4964(a)TK2MSFTNGP05.phx.gbl... > Your second wish: > Here's some code in the form_load event of my email form: > > '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" <leetv(a)CcOoMmCcAaSsTt.net> wrote in message > news:6D55EE62-91D8-477A-AA1F-74E1A24E9A6B(a)microsoft.com... >> one question. >> How can i populate a combo box with the list of outlook SMTP accounts on >> a form? >> thanks >> lee >> >> >> >> "Mark Andrews" <mandrews___NOSPAM___(a)rptsoftware.com> wrote in message >> news:Ojdw5J$3KHA.1452(a)TK2MSFTNGP06.phx.gbl... >>> Boon, >>> >>> 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.la-ongthong(a)cnh.com> wrote in message >>> news:uN4LI383KHA.4336(a)TK2MSFTNGP04.phx.gbl... >>>> Hello, >>>> >>>> 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 >>>> >>>> >>
First
|
Prev
|
Pages: 1 2 Prev: Total filtered record count on filtered adp form Next: Check Table, if found, fill Fields |