472,111 Members | 2,040 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,111 software developers and data experts.

Populating Recurrsive TreeView in ADP using ADO

Hi all,

Apprecite your help in resolving this tricky issue...

I am trying implementing Recurrsive TreeView in MS. Access 2003 ADP
project. So far, no luck :(

The Problem:

This sample snippet is all written for DAO and doesn't work in ADO
(i.e. ADP). Did someone converted this to ADO yet? I'd appreciate for
any further pointer or code snippet using ADO

DAO code >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Option Compare Database
Option Explicit

'=================Load Event for the Form=======================
'Initiates the routine to fill the TreeView control
'================================================= ===========

Private Sub Form_Load()
Const strTableQueryName = "Employees"
Dim db As DAO.Database, rst As DAO.Recordset
Set db = CurrentDb
Set rst = db.OpenRecordset(strTableQueryName, dbOpenDynaset,
dbReadOnly)
AddBranch rst:=rst, strPointerField:="MainMenu", strIDField:="SubMenu",
strTextField:="LastName"
End Sub

'================= AddBranch Sub Procedure ======================
' Recursive Procedure to add branches to TreeView Control
'Requires:
' ActiveX Control: TreeView Control
' Name: xTree
'Parameters:
' rst: Self-referencing Recordset containing the data
' strPointerField: Name of field pointing to parent's primary key
' strIDField: Name of parent's primary key field
' strTextField: Name of field containing text to be displayed
'================================================= ============
Sub AddBranch(rst As Recordset, strPointerField As String, _
strIDField As String, strTextField As String, _
Optional varReportToID As Variant)
On Error GoTo errAddBranch
Dim nodCurrent As Node, objTree As TreeView
Dim strCriteria As String, strText As String, strKey As String
Dim nodParent As Node, bk As String
Set objTree = Me!xTree.Object
If IsMissing(varReportToID) Then ' Root Branch.
strCriteria = strPointerField & " Is Null"
Else ' Search for records pointing to parent.
strCriteria = BuildCriteria(strPointerField, _
rst.Fields(strPointerField).Type, "=" & varReportToID)
Set nodParent = objTree.Nodes("a" & varReportToID)
End If

' Find the first emp to report to the boss node.
rst.FindFirst strCriteria
Do Until rst.NoMatch
' Create a string with LastName.
strText = rst(strTextField)
strKey = "a" & rst(strIDField)
If Not IsMissing(varReportToID) Then 'add new node to the parent
Set nodCurrent = objTree.Nodes.Add(nodParent, tvwChild,
strKey, strText)
Else ' Add new node to the root.
Set nodCurrent = objTree.Nodes.Add(, , strKey, strText)
End If
' Save your place in the recordset so we can pass by ref for
speed.
bk = rst.Bookmark
' Add employees who report to this node.
AddBranch rst, strPointerField, strIDField, strTextField,
rst(strIDField)
rst.Bookmark = bk ' Return to last place and continue search.
rst.FindNext strCriteria ' Find next employee.
Loop

exitAddBranch:
Exit Sub

'--------------------------Error Trapping
--------------------------
errAddBranch:
MsgBox "Can't add child: " & Err.Description, vbCritical,
"AddBranch Error:"
Resume exitAddBranch
End Sub

DAO Code ends>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Best regards

Alix

Nov 13 '05 #1
0 1998

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Janus | last post: by
reply views Thread by N-Mayne | last post: by
2 posts views Thread by Mike | last post: by
reply views Thread by Erland | last post: by
2 posts views Thread by Steve Arndt | last post: by
2 posts views Thread by Maddy | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.