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, 2 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
-
Xfinity home internet
by
MrJimPhelps
27 minutes ago -
Convert PowerPoint presentation to Impress
by
RetiredGeek
2 hours, 27 minutes ago -
Debian 12.11 released
by
Alex5723
10 hours, 53 minutes ago -
Microsoft: Troubleshoot problems updating Windows
by
Alex5723
14 hours, 34 minutes ago -
Woman Files for Divorce After ChatGPT “Reads” Husband’s Coffee Cup
by
Alex5723
57 minutes ago -
Moving fwd, Win 11 Pro,, which is best? Lenovo refurb
by
Deo
11 hours, 3 minutes ago -
DBOS Advanced Network Analysis
by
Kathy Stevens
1 day, 7 hours ago -
Microsoft Edge Launching Automatically?
by
healeyinpa
21 hours, 54 minutes ago -
Google Chrome to block admin-level browser launches for better security
by
Alex5723
1 day, 10 hours ago -
iPhone SE2 Stolen Device Protection
by
Rick Corbett
1 day, 2 hours ago -
Some advice for managing my wireless internet gateway
by
LHiggins
9 hours, 59 minutes ago -
NO POWER IN KEYBOARD OR MOUSE
by
HE48AEEXX77WEN4Edbtm
2 hours, 50 minutes ago -
A CVE-MITRE-CISA-CNA Extravaganza
by
Nibbled To Death By Ducks
1 day, 19 hours ago -
Sometimes I wonder about these bots
by
Susan Bradley
1 day, 15 hours ago -
Does windows update component store “self heal”?
by
Mike Cross
1 day, 5 hours ago -
Windows 11 Insider Preview build 27858 released to Canary
by
joep517
2 days, 9 hours ago -
Pwn2Own Berlin 2025: Day One Results
by
Alex5723
17 hours, 33 minutes ago -
Windows 10 might repeatedly display the BitLocker recovery screen at startup
by
Susan Bradley
6 hours, 12 minutes ago -
Windows 11 Insider Preview Build 22631.5409 (23H2) released to Release Preview
by
joep517
2 days, 12 hours ago -
Windows 10 Build 19045.5912 (22H2) to Release Preview Channel
by
joep517
2 days, 12 hours ago -
Kevin Beaumont on Microsoft Recall
by
Susan Bradley
2 days ago -
The Surface Laptop Studio 2 is no longer being manufactured
by
Alex5723
2 days, 20 hours ago -
0Patch, where to begin
by
cassel23
2 days, 14 hours ago -
CFPB Quietly Kills Rule to Shield Americans From Data Brokers
by
Alex5723
3 days, 10 hours ago -
89 million Steam account details just got leaked,
by
Alex5723
2 days, 21 hours ago -
KB5058405: Linux – Windows dual boot SBAT bug, resolved with May 2025 update
by
Alex5723
3 days, 18 hours ago -
A Validation (were one needed) of Prudent Patching
by
Nibbled To Death By Ducks
3 days, 9 hours ago -
Master Patch Listing for May 13, 2025
by
Susan Bradley
11 hours, 48 minutes ago -
Installer program can’t read my registry
by
Peobody
3 hours, 42 minutes ago -
How to keep Outlook (new) in off position for Windows 11
by
EspressoWillie
3 days, 7 hours ago
Recent blog posts
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.