UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Moving Outlook Automation From 2007 To A2016, Access 2016    
 
   
pere_de_chipstic...
post Mar 8 2018, 10:52 AM
Post#1


UtterAccess Editor
Posts: 10,236
Joined: 8-November 07
From: South coast, England


Hi All

i have used the following code for many years to list the available inbox folders in a drop down on an A2007 form:

CODE
Private Sub Form_Load()
On Error GoTo err_proc

    Dim objOutlook As Outlook.Application
    Dim objNamespace As Outlook.NameSpace
    Dim objFolder As Outlook.MAPIFolder

    Set objOutlook = CreateObject("Outlook.Application")
    Set objNamespace = objOutlook.GetNamespace("MAPI")

    Me.MusReplyEmailFldr.RowSource = ""
    For Each objFolder In objNamespace.Folders("Personal Folders").Folders("InBox").Folders    '<--- FAILS HERE in A2016
        Me.MusReplyEmailFldr.AddItem objFolder.Name
    Next

  
exit_Proc:
On Error Resume Next
    Set objNamespace = Nothing
    Set objOutlook = Nothing
    Exit Sub
    
err_proc:
    Debug.Print Err.Number
    MsgBox Err.Number & Chr(13) & Err.Description, , "Import Outlook"
    Resume exit_Proc
    

End Sub


While this works in Access / Outlook 2007, if fails in A2016 on the line "For Each objFolder In objNamespace.Folders("Personal Folders").Folders("InBox").Folders"
with an error:
Error number -2147221233
"The attempted operation failed. An object could not be found."

Can anyone point me in the right direction for this in A2016?

Many thanks

--------------------
Warm regards
Bernie
Go to the top of the page
 
pere_de_chipstic...
post Mar 8 2018, 01:08 PM
Post#2


UtterAccess Editor
Posts: 10,236
Joined: 8-November 07
From: South coast, England


Seem to have a solution, which is to change

For Each objFolder In objNamespace.Folders("Personal Folders").Folders("InBox").Folders

to

For Each objFolder In objNamespace.Folders([emailAddress]).Folders("InBox").Folders

--------------------
Warm regards
Bernie
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    18th June 2018 - 02:35 PM