Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Better, more compact way to MAPI in Outlook...?

Status
Not open for further replies.

PerlIsGood

Programmer
Jan 24, 2002
154
US
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?

Code:
  If txtCandName.Value <> &quot;&quot; Then
    Set oNsP = Application.GetNameSpace(&quot;MAPI&quot;)
    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 = &quot;Mailbox - Recruiting, Chicago&quot; 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 = &quot;Inbox&quot; 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 = &quot;Entry/Intern 02-03&quot; 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 = &quot;Mid-Level 02-03&quot; 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 (&quot;No Candidate Name was supplied.&quot;), vbOKOnly, &quot;Error:  Candidate Field Empty&quot;
    Folder_Count = 1
  End If
Notorious P.I.G.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top