Can anyone tell me how to populate a TreeView Control with Outlook folders? I have never used the TreeView control, so please be gentle.
Thanks!
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
Populate TreeView control with Outlook folders (Access 2002)
Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Populate TreeView control with Outlook folders (Access 2002)
- This topic has 14 replies, 5 voices, and was last updated 22 years, 3 months ago.
AuthorTopicWSlmarrero
AskWoody LoungerMarch 18, 2003 at 8:59 pm #384926Viewing 0 reply threadsAuthorReplies-
WSHansV
AskWoody Lounger -
WSlmarrero
AskWoody LoungerMarch 19, 2003 at 12:52 pm #662267Do you have a better idea? I am creating an application that checks “generic” e-mail addresses for our company, responds with a message telling the customer that we have received their message and forwards the message to someone at our helpdesk. I have completed everything except I don’t know how to make it show the Outlook folders in an Access form. I can get it to take me to Outlook so I can pick the folder I want monitored, but I don’t know how to get it to show me the folders in a form. I thought the Treeview control would work.
-
WSHansV
AskWoody LoungerMarch 19, 2003 at 1:08 pm #662270It is quite possible, I only wanted to point out that it is not a specific Access question.
You could place a treeview control on a form, and populate it in the OnLoad event of the form. The following code will only generate the first level, for subfolders, you would need a recursive approach. The treeview control is named tvw, and the code assumes you have a reference to the Microsoft Outlook 10.0 Object Library.
Private Sub Form_Load()
Dim olApp As Outlook.Application
Dim olNameSpace As Outlook.NameSpace
Dim olFolder As Outlook.MAPIFolder
Dim tvNode As MSComctlLib.Node
Dim tvRoot As MSComctlLib.Node
Set olApp = GetObject(, “Outlook.Application”)
Set tvRoot = tvw.Nodes.Add(Key:=”Outlook”, Text:=”Outlook”)
Set olNameSpace = olApp.GetNamespace(“MAPI”)
For Each olFolder In olNameSpace.Folders
Set tvNode = tvw.Nodes.Add(Key:=olFolder.Name, Text:=olFolder.Name, _
Relative:=tvRoot, Relationship:=tvwChild)
Next olFolder
End SubSee if you can adapt this; post back if you need more help.
-
WSlmarrero
AskWoody Lounger -
WSHansV
AskWoody LoungerMarch 19, 2003 at 2:41 pm #662288I don’t have the time now to give a complete example. After
Set tvNode = tvw.Nodes.Add(Key:=olFolder.Name, Text:=olFolder.Name, _
Relative:=tvRoot, Relationship:=tvwChild)you should insert a call to a procedure or function that takes olFolder and loops through its subfolders, adding them as child nodes to tvNode. For each subfolder, call the same procedure again, etc. The process will stop automatically if a folder has no subfolders.
If you need more help, I will put up an example later on, or perhaps somebody else will jump in.
-
WSlmarrero
AskWoody Lounger
-
-
-
WBell
AskWoody_MVPMarch 19, 2003 at 3:59 pm #662306This is a pretty ambitious application you are building – if you get it to work it might be marketable! But I have some questions and comments.
What is the purpose of your form you are creating? If I were doing this, it would be with Automation, and everything would be done under the covers rather than using forms. In addition, I would be doing this in Exchange Server rather than in Access. It seems to me the only purpose served by Access is to handle email, which isn’t exactly its forte.
Finally, the TreeView control that you are attempting to use is a complex ActiveX control, and is normally used in conjunction with the Image control. Programming to support the the two of those controls is a complex and error-prone task which requires a great deal of research to begin with. Hans has given you a jumping off place, but the background knowledge require to make effective use of it is probably beyond the scope of what the Lounge can do. I would suggest you spend a fair bit of time exploring the information available on the MS Knowledge Base – do a search on Treeview Access How To and you will get a large number of articles dealing with the treeview, bugs, and so on. In particular, this KB Article ACC2000: How To Fill a TreeView Control Recursively may answer some questions, but in probability generate a lot more.
-
WSlmarrero
AskWoody LoungerMarch 19, 2003 at 4:18 pm #662310The form I am creating is where the user goes to make their choices as to what they want to do with the e-mails that come in. They would choose the source folder and the destination folder (which is where I would use the TreeView Control), the e-mail addresses they want to forward the e-mails to, the subject and body of the e-mail they want to send to the customer and the time interval at which the application should check the mailbox. Each department has their own e-mail address and they should be able to modify the messages that go out to the customers, as well as the e-mail adddress that the incoming mail is sent to.
The reason I’m doing it in Access is because it is the program I am most familiar with. I would have no idea where to begin creating something in Exchange Server and my Tech Support Department doesn’t know how to do it either.
Thanks for the recommendation on the Microsoft article. I have already gone there and you are correct, it generated more questions than it answered. I will continue to try until I figure it out.
-
WSHansV
AskWoody LoungerMarch 19, 2003 at 6:49 pm #662335As Wendell has rightly remarked, you may be in for more than you expected.
Still, if you want to continue, here is code to populate the treeview recursively. Apart from being called in the OnLoad of a form, there is nothing specific to Access; this code will work as well on an Excel or Word userform, or in VB6.
I have added cleaning up of object variables.
Private Sub Form_Load()
Dim olApp As Outlook.Application
Dim olNameSpace
Dim olFolder As Outlook.MAPIFolder
Dim tvNode As MSComctlLib.Node
Dim tvRoot As MSComctlLib.NodeSet olApp = GetObject(, “Outlook.Application”)
Set tvRoot = tvw.Nodes.Add(Text:=”Outlook”)
Set olNameSpace = olApp.GetNamespace(“MAPI”)‘ This call populates the tree view
GetSubFolders olNameSpace, tvRootSet tvNode = Nothing
Set olFolder = Nothing
Set olNameSpace = Nothing
Set tvRoot = Nothing
Set olApp = Nothing
End SubPrivate Sub GetSubFolders(olFolder, tvNode As MSComctlLib.Node)
Dim tvChild As MSComctlLib.Node
Dim olSubFolder As Outlook.MAPIFolderFor Each olSubFolder In olFolder.Folders
Set tvChild = tvw.Nodes.Add(Text:=olSubFolder.Name, _
Relative:=tvNode, Relationship:=tvwChild)
‘ Call procedure recursively
GetSubFolders olSubFolder, tvChild
Next olSubFolderSet olSubFolder = Nothing
Set tvChild = Nothing
End SubTo do something with the tree view, write code in the tvw_NodeClick event. This event has an argument Node that represents the node clicked by the user. Here is a trivial example:
Private Sub tvw_NodeClick(ByVal Node As Object)
MsgBox “You clicked ” & Node.Text
End Sub -
WSbushaw
AskWoody LoungerMarch 19, 2003 at 9:34 pm #662387Hans,
I’m trying out your code, but it’s getting hung up with the object ‘tvw’ being undefined. How should it be defined? I poked around in the MSComctlLib library but couldn’t find anything obvious — I’m strectching my comfort zone here, so this may have a simple answer that I’m missing.
Thanks.
-
WSBrentD
AskWoody Lounger -
WSbushaw
AskWoody Lounger -
WSBrentD
AskWoody LoungerMarch 19, 2003 at 9:58 pm #662396 -
WBell
AskWoody_MVPMarch 19, 2003 at 7:42 pm #662346Well, if this is being done in Outlook, why not used it as your platform. Outlook 2002 has a relatively robust development environment (not like Access, but far better than 97/98), and you don’t have to mess with the treeview. In fact, it seems to me that your Access solution won’t offer much if any advantage over simply doing things manually in Outlook. Am I missing something big here?
-
-
-
-
Viewing 0 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Perplexity Pro free for 12 mos for Samsung Galaxy phones
by
Patricia Grace
1 hour, 59 minutes ago -
June KB5060842 update broke DHCP server service
by
Alex5723
31 minutes ago -
AMD Ryzen™ Chipset Driver Release Notes 7.06.02.123
by
Alex5723
4 hours, 34 minutes ago -
Excessive security alerts
by
WSSebastian42
15 minutes ago -
* CrystalDiskMark may shorten SSD/USB Memory life
by
Alex5723
14 hours, 2 minutes ago -
Ben’s excellent adventure with Linux
by
Ben Myers
36 minutes ago -
Seconds are back in Windows 10!
by
Susan Bradley
1 hour, 11 minutes ago -
WebBrowserPassView — Take inventory of your stored passwords
by
Deanna McElveen
11 hours, 5 minutes ago -
OS news from WWDC 2025
by
Will Fastie
15 hours, 16 minutes ago -
Need help with graphics…
by
WSBatBytes
2 hours, 1 minute ago -
AMD : Out of Bounds (OOB) read vulnerability in TPM 2.0 CVE-2025-2884
by
Alex5723
1 day, 5 hours ago -
Totally remove or disable BitLocker
by
CWBillow
4 hours, 38 minutes ago -
Windows 10 gets 6 years of ESU?
by
n0ads
7 hours, 53 minutes ago -
Apple, Google stores still offer China-based VPNs, report says
by
Nibbled To Death By Ducks
1 day, 16 hours ago -
Search Forums only bring up my posts?
by
Deo
1 day, 16 hours ago -
Windows Spotlight broken on Enterprise and Pro for Workstations?
by
steeviebops
2 days, 3 hours ago -
Denmark wants to dump Microsoft for Linux + LibreOffice
by
Alex5723
1 day, 20 hours ago -
How to get Microsoft Defender to honor Group Policy Setting
by
Ralph
2 days, 4 hours ago -
Apple : Paragon’s iOS Mercenary Spyware Finds Journalists Target
by
Alex5723
2 days, 14 hours ago -
Music : The Rose Room – It’s Been A Long, Long Time album
by
Alex5723
2 days, 15 hours ago -
Disengage Bitlocker
by
CWBillow
2 days, 5 hours ago -
Mac Mini M2 Service Program for No Power Issue
by
Alex5723
2 days, 17 hours ago -
New Win 11 Pro Geekom Setup questions
by
Deo
1 day, 16 hours ago -
Windows 11 Insider Preview build 26200.5651 released to DEV
by
joep517
3 days, 1 hour ago -
Windows 11 Insider Preview build 26120.4441 (24H2) released to BETA
by
joep517
3 days, 1 hour ago -
iOS 26,, MacOS 26 : Create your own AI chatbot
by
Alex5723
3 days, 5 hours ago -
New PC transfer program recommendations?
by
DaveBoston
1 day, 9 hours ago -
Windows 11 Insider Preview Build 22631.5545 (23H2) released to Release Preview
by
joep517
3 days, 9 hours ago -
Windows 10 Build 19045.6029 (22H2) to Release Preview Channel
by
joep517
3 days, 9 hours ago -
Best tools for upgrading a Windows 10 to an 11
by
Susan Bradley
2 days, 21 hours ago
Recent blog posts
- Ben’s excellent adventure with Linux
- Seconds are back in Windows 10!
- WebBrowserPassView — Take inventory of your stored passwords
- OS news from WWDC 2025
- Best tools for upgrading a Windows 10 to an 11
- Master patch listing for June 10, 2025
- 24H2 may not be offered June updates
- June 2025 updates are out
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.