ed coleman
Registered User.
- Local time
- Today, 08:55
- Joined
- Nov 8, 2012
- Messages
- 44
Trying to get vba so that my AR Collection person can click on past due customers, look at their account, make comments and then send an email with the account attached. I seem to have that process working well.
My problem stems from the fact that we run two companies with two different email address, and depending on the customer, one or the other should be selected. Currently, only one is selected for ALL customers.
I would appreciate some assistance with programmatically changing the FROM email based on the customer. The code below generates an email, however, it doesn't change the From address based on the company that responsible for the customer.
Private Sub Command10_Click()
Me.Refresh
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strReportName As String
Dim strmessagebody As String
Dim strto As String
Dim appOut As Outlook.Application
Dim oAccount As Outlook.Account
Dim strAccount As String
Dim oMail As Outlook.MailItem 'ADDED 4/11/2019
Set appOut = New Outlook.Application
Set oMail = appOut.CreateItem(olMailItem) 'ADDED 4/11/2019
If Reports!rpt_os_ar_by_cust_except!Text87 = "Boxes Next Day" Then
strAccount = Reports!rpt_os_ar_by_cust_except!Text12 & "@boxesnextday.com"
Else
strAccount = Reports!rpt_os_ar_by_cust_except!Text12 & "@colemancontainers.com"
End If
Set oAccount = appOut.Session.Accounts(strAccount)
strReportName = "rpt_os_ar_by_cust_except"
strmessagebody = IIf(IsNull(Forms!frmselcommentsforemail!Text5), "", Forms!frmselcommentsforemail!Text5)
strto = Reports!rpt_os_ar_by_cust_except!Text124
'Debug.Print Reports!rpt_os_ar_by_cust_except!Text124
Me.Refresh
strBody = "<P STYLE='font-family:calibri;font-size:14.5px'/P>"
DoCmd.OutputTo acOutputReport, strReportName, acFormatPDF, CurrentProject.Path & "" & strReportName & ".pdf", False
'******************************* USER DEFINED SECTION ********************************
strSubject = "Outstanding Invoices"
'*************************************************************************************
With oMail
'On Error Resume Next
.To = strto
.cc = Reports!rpt_os_ar_by_cust_except!Text126
.HTMLBody = strBody & "Attn: " & Reports!rpt_os_ar_by_cust_except.Text122 & "," & (Chr(13) + Chr(10)) & (Chr(13) + Chr(10)) & "<br>" & "<br>" & strmessagebody
.Subject = strSubject & " for " & Reports!rpt_os_ar_by_cust_except!CSNAME & " (This is a " & Reports!rpt_os_ar_by_cust_except!Text87 & " Company)"
.Attachments.Add CurrentProject.Path & "" & strReportName & ".pdf"
'Set .SendUsingAccount = oAccount
.Display 'VIEW email before sending
'.Send 'Immediately Sends the E-Mail without displaying Outlook
End With
Set oAccount = Nothing
Set appOut = Nothing
DoCmd.Close acReport, "rpt_os_ar_by_cust_except"
DoCmd.Close acForm, "frmselcommentsforemail"
End Sub
My problem stems from the fact that we run two companies with two different email address, and depending on the customer, one or the other should be selected. Currently, only one is selected for ALL customers.
I would appreciate some assistance with programmatically changing the FROM email based on the customer. The code below generates an email, however, it doesn't change the From address based on the company that responsible for the customer.
Private Sub Command10_Click()
Me.Refresh
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strReportName As String
Dim strmessagebody As String
Dim strto As String
Dim appOut As Outlook.Application
Dim oAccount As Outlook.Account
Dim strAccount As String
Dim oMail As Outlook.MailItem 'ADDED 4/11/2019
Set appOut = New Outlook.Application
Set oMail = appOut.CreateItem(olMailItem) 'ADDED 4/11/2019
If Reports!rpt_os_ar_by_cust_except!Text87 = "Boxes Next Day" Then
strAccount = Reports!rpt_os_ar_by_cust_except!Text12 & "@boxesnextday.com"
Else
strAccount = Reports!rpt_os_ar_by_cust_except!Text12 & "@colemancontainers.com"
End If
Set oAccount = appOut.Session.Accounts(strAccount)
strReportName = "rpt_os_ar_by_cust_except"
strmessagebody = IIf(IsNull(Forms!frmselcommentsforemail!Text5), "", Forms!frmselcommentsforemail!Text5)
strto = Reports!rpt_os_ar_by_cust_except!Text124
'Debug.Print Reports!rpt_os_ar_by_cust_except!Text124
Me.Refresh
strBody = "<P STYLE='font-family:calibri;font-size:14.5px'/P>"
DoCmd.OutputTo acOutputReport, strReportName, acFormatPDF, CurrentProject.Path & "" & strReportName & ".pdf", False
'******************************* USER DEFINED SECTION ********************************
strSubject = "Outstanding Invoices"
'*************************************************************************************
With oMail
'On Error Resume Next
.To = strto
.cc = Reports!rpt_os_ar_by_cust_except!Text126
.HTMLBody = strBody & "Attn: " & Reports!rpt_os_ar_by_cust_except.Text122 & "," & (Chr(13) + Chr(10)) & (Chr(13) + Chr(10)) & "<br>" & "<br>" & strmessagebody
.Subject = strSubject & " for " & Reports!rpt_os_ar_by_cust_except!CSNAME & " (This is a " & Reports!rpt_os_ar_by_cust_except!Text87 & " Company)"
.Attachments.Add CurrentProject.Path & "" & strReportName & ".pdf"
'Set .SendUsingAccount = oAccount
.Display 'VIEW email before sending
'.Send 'Immediately Sends the E-Mail without displaying Outlook
End With
Set oAccount = Nothing
Set appOut = Nothing
DoCmd.Close acReport, "rpt_os_ar_by_cust_except"
DoCmd.Close acForm, "frmselcommentsforemail"
End Sub