Link to home
Start Free TrialLog in
Avatar of JackStapleton
JackStapleton

asked on

Access 2007, Outlook 2007, MAPI, Loop through items in .PickFolder

So, this code works fine to open the outlook picker and select a folder and iterate through the items in the collection and import them into a access table.  However, instead of using the picker, I would like to use the value from a form field where the user can store the text of the name of the folder in outlook.  I thought Set MyFolder = objNS.Folders(Me.OutlookFolderName) would work, but it does not.  Please help...

Dim OlApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim MyFolder As Outlook.MAPIFolder
Dim Mailobject As Object
Dim dealer As Integer

Dim rs As Recordset
Dim db As Database
Set db = CurrentDb
Set rs = db.OpenRecordset("tbl_outlooktemp")
   
Set OlApp = Outlook.Application
Set objNS = OlApp.GetNamespace("MAPI")
Set MyFolder = objNS.PickFolder
   
    For Each Mailobject In MyFolder.Items
    Me.OutlookFolderName = MyFolder
        With rs
            .AddNew
                !Subject = Mailobject.Subject
                !From = Mailobject.SenderName
                !To = Mailobject.To
                !Body = Mailobject.Body
                !DateSent = Mailobject.SentOn
                !SenderEmailAddress = Mailobject.SenderEmailAddress
                !SenderEmailType = Mailobject.SenderEmailType
                !CC = Mailobject.CC
                !BCC = Mailobject.BCC
                !Importance = Mailobject.Importance
                !Sensitivity = Mailobject.Sensitivity
                !EntryID = Mailobject.EntryID
            .Update
        End With
    Next

Set objNS = Nothing
Set MyFolder = Nothing
Set OlApp = Nothing
Set objNS = Nothing
ASKER CERTIFIED SOLUTION
Avatar of peakpeak
peakpeak
Flag of Sweden image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial