This adjustment adds message subjects to the appropriate node, just in case you wanted that:

VB Code:
  1. Private Sub cmdGetFolders_Click()
  2. 'Required Treeview Control named tvw
  3. 'Reference to Microsoft Outlook 9.0 Object Library
  4.     Dim oApp As Outlook.Application
  5.     Dim oNameSpace As NameSpace
  6.     Dim oFolder As MAPIFolder
  7.     Dim oMailItem As Object
  8.     Dim cFolder As MAPIFolder
  9.     Dim sFolder As MAPIFolder
  10.     Dim myItems As Items
  11.     Dim MailCounter As Integer, FolderCount As Integer
  12.     Dim sMessage As String
  13.     Set oApp = New Outlook.Application
  14.     Set oNameSpace = oApp.GetNamespace("MAPI")
  15.     Set oFolder = oNameSpace.GetDefaultFolder(olFolderInbox)
  16.     tvw.Nodes.Add , , "inbox", oFolder
  17.     mCounter = 0
  18.     For Each oMailItem In oFolder.Items
  19.     mCounter = mCounter + 1
  20.             tvw.Nodes.Add "inbox", tvwChild, "mailmsg" & mCounter, "MAIL: " & oMailItem
  21.         Next
  22.     For FolderCount = 1 To oFolder.Folders.Count
  23.         Set cFolder = oFolder.Folders(FolderCount)
  24.         tvw.Nodes.Add "inbox", tvwChild, "mail" & FolderCount, cFolder
  25.         For Each oMailItem In cFolder.Items
  26.         mCounter = mCounter + 1
  27.             tvw.Nodes.Add "mail" & FolderCount, tvwChild, "mailmsg" & mCounter, "MAIL: " & oMailItem
  28.         Next
  29.         If cFolder.Folders.Count <> 0 Then 'check for 1 more layer of sub folders
  30.             For nFolderCount = 1 To oFolder.Folders.Count
  31.                 Set sFolder = oFolder.Folders(nFolderCount)
  32.                 If sFolder <> cFolder Then
  33.                 tvw.Nodes.Add "mail" & FolderCount, tvwChild, "mail" & FolderCount & nFolderCount, sFolder
  34.                 For Each oMailItem In sFolder.Items
  35.                     mCounter = mCounter + 1
  36.                     tvw.Nodes.Add "mail" & FolderCount & nFolderCount, tvwChild, "mailmsg" & mCounter, "MAIL: " & oMailItem
  37.                    Next
  38.                    End If
  39.             Next
  40.         End If
  41.     Next
  42.     Set oMailItem = Nothing
  43.     Set oFolder = Nothing
  44.     Set mFolder = Nothing
  45.     Set oNameSpace = Nothing
  46.     Set oApp = Nothing
  47. End Sub