Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-11-2022, 11:58 AM
RMittelman RMittelman is offline Issue Automating an Outlook Email from Access Windows 10 Issue Automating an Outlook Email from Access Office 2016
Novice
Issue Automating an Outlook Email from Access
 
Join Date: Dec 2010
Posts: 18
RMittelman is on a distinguished road
Default Issue Automating an Outlook Email from Access

I have the following code in an Outlook class in my Access database:

Code:
Public Sub CreateEMail(strETo As String, strECC As String, strESubject As String, strEBody As String, _
                       ParamArray attachFiles() As Variant)

    Dim attachFile  As Variant
    
    Set olEmail = olApp.CreateItem(olMailItem)
    With olEmail
        
        .To = strETo
        .CC = strECC
        If Not IsNull(olAccount) Then
            .SendUsingAccount = olAccount
            .Sender = olAccount
        End If
        .Subject = strESubject
        .HTMLBody = strEBody & "<br>" & .HTMLBody
        
'        .body = Application.plainText(strEBody) & vbCrLf & .body
        
        For Each attachFile In attachFiles
            If attachFile <> "" Then .Attachments.Add attachFile
        Next
        
        If m_autoSend Then
            .Send
        Else
            .Display
        End If
        
    End With

End Sub
Since I happen to have 2 different email addresses, I've previously set the variable olAccount to the preferred address. This variable is declared as Variant.

When the code is executed, I end up with an open Outlook email message ready to complete and send. This is good.

What's not good is the wrong email address (number 1 in my account list) is shown in the message, and I need to click the drop-down and choose the correct one (number 2 in my account list) in the message UI.

If I single step the code, the correct Outlook account is being chosen, but when the outgoing message is displayed, it's the wrong account.



Any ideas to fix this? Thanks...
Reply With Quote
Reply

Tags
automating outlook, vba

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot Access Email in MS 365 - Licensing Issue? DeborahG Outlook 0 06-01-2020 08:16 AM
Issue Automating an Outlook Email from Access Unable to access Outlook.com email account using Outlook 2007. MACH1 Outlook 3 07-03-2016 03:18 AM
Can't create new email or access email acounts Outlook 2003 onthebeaches Outlook 1 02-20-2012 10:21 PM
Issue Automating an Outlook Email from Access Automating Mailmerge from Access PhilAJ Mail Merge 4 05-23-2011 04:42 AM
Issue Automating an Outlook Email from Access Automating Outlook from Access RMittelman Outlook 1 02-07-2011 03:11 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:30 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft