Results 1 to 5 of 5
  1. #1
    crowegreg is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Posts
    398

    Using the Outlook Object

    Hello,

    I've previously written Access VBA to send an email through Outlook. I'm now on an exchange server, and I can't figure out how to get my Access VBA to recognize my multiple mailbox accounts within Exchange, and set the account I'd like the emails to be sent from.

    Here's what I've tried:
    Code:
                Dim olApp As Outlook.Application
                Dim olOutlookMsg As Outlook.MailItem
                Dim olAccount As Outlook.Account
    
                For Each olAccount In Outlook.Application.Session.Accounts
    
                    If olAccount = "PMA@cthol.net" Then
                
                        Set olApp = GetObject(, "Outlook.Application")
                        'Create the message.
                        Set olOutlookMsg = olApp.CreateItem(olMailItem)
    
                        With olOutlookMsg
                            .To = strEmailAddress
                            .SendUsingAccount = olAccount
                            .Subject = "Details"
                            .HTMLBody = strBody
                            .Send       'Go ahead and send right away
                        End With
    
                    End If
                Next
    
                Set olOutlookMsg = Nothing
                Set olApp = Nothing
                Set olAccount = Nothing
    The code above produces no error message. When I execute the code, the for next loop starts with my personal account "gc@cthol.net", goes to the next record, which displays "Live Meeting Transport", then it exits the for next loop.
    I've looked into using either the "Store" or "Stores" object(s), but I can't figure anything out.


    Thank you in advance!!

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Maybe something like this would be helpful.
    Code:
    Dim oApp As New Outlook.Application
    Dim oNamespace As Outlook.NameSpace
    Dim oAccounts As Outlook.Accounts
    Dim oAccount As Outlook.account
    Dim intCount As Integer
    intCount = 1
        
    Set oNamespace = oApp.Session
    Set oAccounts = oNamespace.Accounts
        
        For Each oAccount In oAccounts
            Debug.Print oAccount.DisplayName
            Debug.Print oNamespace.Accounts.Item(intCount) & " is Item: " & intCount
            intCount = intCount + 1
        Next
        
    Set oAccounts = Nothing
    Set oNamespace = Nothing
    Set oApp = Nothing

  3. #3
    crowegreg is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Posts
    398
    Thank you for the response.

    I get the same results. The for loop only finds the two accounts I previously listed.

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    IIRC, if you use Outlook to connect to exchange AND create an account within Outlook, you will see it in the Accounts collection. I have a tested code snippet specific to Exchange. It is not on this computer, though. So, the code in my previous post is not tested with exchange. But, I don't think that matters.

    I believe there are settings on Exchange that allow or disallow keeping copies of emails on the local client. However, this memory is vague and distant.

    Are you using Exchange Online? Maybe you can log in and see what you can see from the Admin panel.

  5. #5
    crowegreg is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Posts
    398
    Hello,
    Not using Exchange online. I don't have rights to the Admin panel. I'll try and connect with my Exchange admin to see if their is a setting that can be changed.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 05-02-2016, 04:33 AM
  2. Replies: 0
    Last Post: 02-13-2015, 02:24 PM
  3. Replies: 3
    Last Post: 09-18-2014, 07:13 AM
  4. Object Variable Not Set when Outlook is running
    By chris.williams in forum Programming
    Replies: 3
    Last Post: 10-03-2012, 02:33 PM
  5. Outlook Object Model question - automation
    By yeah in forum Programming
    Replies: 1
    Last Post: 11-23-2010, 02:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums