Results 1 to 15 of 15
  1. #1
    New Lounger
    Join Date
    Mar 2003
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Populate TreeView control with Outlook folders (Access 2002)

    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!

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Populate TreeView control with Outlook folders (Access 2002)

    This is hardly an Access question - the Treeview control is not a native Access control, but a VB6 control, and you want to populate it with folders from yet another application: Outlook.

  3. #3
    New Lounger
    Join Date
    Mar 2003
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Populate TreeView control with Outlook folders (Access 2002)

    Do 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.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Populate TreeView control with Outlook folders (Access 2002)

    It 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 Sub

    See if you can adapt this; post back if you need more help.

  5. #5
    New Lounger
    Join Date
    Mar 2003
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Populate TreeView control with Outlook folders (Access 2002)

    Thanks, that worked great. I don't know what you mean by a "recursive" approach for the 2nd level. Can you please explain?

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Populate TreeView control with Outlook folders (Access 2002)

    I 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.

  7. #7
    New Lounger
    Join Date
    Mar 2003
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Populate TreeView control with Outlook folders (Access 2002)

    Thanks again for your help. I'll try that.

  8. #8
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,623
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: Populate TreeView control with Outlook folders (Access 2002)

    This 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.
    Wendell

  9. #9
    New Lounger
    Join Date
    Mar 2003
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Populate TreeView control with Outlook folders (Access 2002)

    The 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.

  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Populate TreeView control with Outlook folders (Access 2002)

    As 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.Node

    Set olApp = GetObject(, "Outlook.Application")
    Set tvRoot = tvw.Nodes.Add(Text:="Outlook")
    Set olNameSpace = olApp.GetNamespace("MAPI")

    ' This call populates the tree view
    GetSubFolders olNameSpace, tvRoot

    Set tvNode = Nothing
    Set olFolder = Nothing
    Set olNameSpace = Nothing
    Set tvRoot = Nothing
    Set olApp = Nothing
    End Sub

    Private Sub GetSubFolders(olFolder, tvNode As MSComctlLib.Node)
    Dim tvChild As MSComctlLib.Node
    Dim olSubFolder As Outlook.MAPIFolder

    For Each olSubFolder In olFolder.Folders
    Set tvChild = tvw.Nodes.Add(Text:=olSubFolder.Name, _
    Relative:=tvNode, Relationship:=tvwChild)
    ' Call procedure recursively
    GetSubFolders olSubFolder, tvChild
    Next olSubFolder

    Set olSubFolder = Nothing
    Set tvChild = Nothing
    End Sub

    To 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

  11. #11
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,623
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: Populate TreeView control with Outlook folders (Access 2002)

    Well, 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?
    Wendell

  12. #12
    4 Star Lounger
    Join Date
    Feb 2001
    Location
    Richland, Washington, USA
    Posts
    407
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Populate TreeView control with Outlook folders (Access 2002)

    Hans,

    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.

  13. #13
    Lounger
    Join Date
    Jan 2003
    Location
    Herndon, Virginia, USA
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Populate TreeView control with Outlook folders

    Hi Tom, you'll need to add a Microsoft Treeview Control to the form and name it "tvw". That'll solve the problem.

    Brent

  14. #14
    4 Star Lounger
    Join Date
    Feb 2001
    Location
    Richland, Washington, USA
    Posts
    407
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Populate TreeView control with Outlook folders

    Thanks, Brent. His tvw_NodeClick routine should have clued me in! I had created the ActiveX control on the form; I just hadn't renamed it to tvw.
    <img src=/S/smash.gif border=0 alt=smash width=30 height=26> <font face="Georgia"><--- Brent & Hans</font face=georgia>
    <img src=/S/doh.gif border=0 alt=doh width=15 height=15> <font face="Georgia"><--- Tom</font face=georgia>

  15. #15
    Lounger
    Join Date
    Jan 2003
    Location
    Herndon, Virginia, USA
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Populate TreeView control with Outlook folders

    Don't feel bad about this. I can't tell you the number of times I've done similar things -- especially working with the horribly poorly documented treeview control. If I ever figure out how to use it even reasonably well, I'll put together a guide to programming it...

    Brent

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •