PerlIsGood
Programmer
So I went and figured out how to programatically navigate Outlook's folder listings last night. My only problem (or minor concern) is that the code I wrote seems overly complex.
What I need to do is go from the {USER}'s mailbox, find the {RECRUITING} mailbox (a separate Exchange account which these users will have running), and then find a specific sub-sub folder under that account's inbox.
The below works. Is there any way to streamline it?
Notorious P.I.G.
What I need to do is go from the {USER}'s mailbox, find the {RECRUITING} mailbox (a separate Exchange account which these users will have running), and then find a specific sub-sub folder under that account's inbox.
The below works. Is there any way to streamline it?
Code:
If txtCandName.Value <> "" Then
Set oNsP = Application.GetNameSpace("MAPI")
Set oUser_Mailbox = oNsP.Folders
For Each fld_u in oUser_Mailbox
userID = fld_u.EntryID
Set oUser_Folder = oNsP.GetFolderFromID(userID)
If oUser_Folder.Name = "Mailbox - Recruiting, Chicago" Then
Set oRec_Mailbox = oUser_Folder.Folders
For Each fld_r in oRec_Mailbox
recID = fld_r.EntryID
Set oRec_Folder = oNsP.GetFolderFromID(recID)
If oRec_Folder.Name = "Inbox" Then
Set oRec_Inbox = oRec_Folder.Folders
For Each fld_i in oRec_Inbox
inID = fld_i.EntryID
Set oIn_Fld = oNsP.GetFolderFromID(inID)
If oIn_Fld.Name = "Entry/Intern 02-03" Then
Set oEnt_Fols = oIn_Fld.Folders
For Each fld_e in oEnt_Fols
entID = fld_e.EntryID
Set oEn_Fld = oNsP.GetFolderFromID(entID)
If oEn_Fld.Name = txtCandName Then
oEn_Fld.Display
Folder_Count = 1
Exit For
End If
Next
ElseIf oIn_Fld.Name = "Mid-Level 02-03" Then
Set oMid_Fols = oIn_Fld.Folders
For Each fld_m in oMid_Fols
midID = oMid_Fols.EntryID
Set oMid_Fld = oNsP.GetFolderFromID(midID)
If oMid_Fld.Name = txtCandName Then
oMid_Fld.Display
Folder_Count = 1
Exit For
End If
Next
End If
Next
End If
Next
End If
Next
Else
MsgBox ("No Candidate Name was supplied."), vbOKOnly, "Error: Candidate Field Empty"
Folder_Count = 1
End If