troubleshooting Question

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

Avatar of JackStapleton
JackStapleton asked on
Microsoft Access
1 Comment1 Solution1020 ViewsLast Modified:
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
peakpeak

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 1 Comment.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros