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.OutlookFo lderName) 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_outl ooktemp")
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.SenderEmailAddr ess
!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
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_outl
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.SenderEmailAddr
!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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.