M
Matt
Hello NG
I used this VBA code poulate a treeview from a table with different
employees and supervisors (Anybody can be also a supervisor if his PersonlID
is set in the ReportsToID field of an another emplyee).
It worked very well but now I need the [PersonalID] and [ReportsToID] to be
replication IDs.
But for GUID the FindFirst method doesn't work :-(
I searched the net and found the Seek-method but I have no clue how to use
this with the GUID. I can't get it to work I think it has something to do
with the converting of the GUID to String (StringFromGuid) but I'm stuck
here.
Can anybody guide me adapting this code below to work with GUID?
Thank you very much
Regrads
Matt
Private Sub Form_Load()
On Error GoTo ErrForm_Load
Dim nodCurrent As node
Dim strText As String, nodRoot As node
Dim bk As String, node As node
Dim objTree As TreeView
Set db = CurrentDb
Set rst = db.OpenRecordset("tblEmployees", dbOpenDynaset)
If rst.EOF Then
Exit Sub
Else
' Create a reference to the TreeView Control.
Set objTree = Form_Employee!xTree.Object
' Find first Employee without supervisor
rst.FindFirst "[ReportsToID] = 0" 'would be IS NULL using GUID
' Build the TreeView list with supervisor and employees
Do Until rst.NoMatch
' Extract employee_name.
strText = rst![First] & " " & rst![Last]
' Add a root level node to the tree for the parent process
Set nodCurrent = objTree.Nodes.Add(, , "a" & rst!PersonalID, strText,
Int(rst!Image))
' Use a placeholder to save this place in the recordset.
bk = rst.Bookmark
' Run a recursive procedure to add all the child nodes für
AddChildren nodCurrent, rst
' Return to your placeholder.
rst.Bookmark = bk
' Find the next supervisor.
rst.FindNext "[ReportsToID] = 0"
Loop
End Sub
Sub AddChildrenA(nodboss As node, rst As DAO.Recordset)
Dim nodCurrent As node
Dim objTree As TreeView, strText As String, bk As String
Dim db As DAO.Database
'Dim rst As DAO.Recordset
' Create a reference to the TreeView control.
Set objTree = Form_Employee!xTree.Object
' Find the first employee who reports to the supervisor for this
' node.
rst.FindFirst "[ReportsToID] =" & Mid(nodboss.Key, 2)
' Build the list of employees who report to this supervisor.
Do Until rst.NoMatch
' Extract the employee's name.
strText = rst![First] & " " & rst![Last]
' Add as a child node to the tree.
Set nodCurrent = objTree.Nodes.Add(nodboss, tvwChild, "a" &
rst!PersonalID, strText, Int(rst!Image))
' Save your place in the recordset.
bk = rst.Bookmark
' Add any employees for whom the current node is a supervisor.
AddChildren nodCurrent, rst
' Return to your place in the recordset and continue to search.
rst.Bookmark = bk
' Find the next employee who reports to this supervisor.
rst.FindNext "[ReportsToID]=" & Mid(nodboss.Key, 2)
Loop
End Sub
I used this VBA code poulate a treeview from a table with different
employees and supervisors (Anybody can be also a supervisor if his PersonlID
is set in the ReportsToID field of an another emplyee).
It worked very well but now I need the [PersonalID] and [ReportsToID] to be
replication IDs.
But for GUID the FindFirst method doesn't work :-(
I searched the net and found the Seek-method but I have no clue how to use
this with the GUID. I can't get it to work I think it has something to do
with the converting of the GUID to String (StringFromGuid) but I'm stuck
here.
Can anybody guide me adapting this code below to work with GUID?
Thank you very much
Regrads
Matt
Private Sub Form_Load()
On Error GoTo ErrForm_Load
Dim nodCurrent As node
Dim strText As String, nodRoot As node
Dim bk As String, node As node
Dim objTree As TreeView
Set db = CurrentDb
Set rst = db.OpenRecordset("tblEmployees", dbOpenDynaset)
If rst.EOF Then
Exit Sub
Else
' Create a reference to the TreeView Control.
Set objTree = Form_Employee!xTree.Object
' Find first Employee without supervisor
rst.FindFirst "[ReportsToID] = 0" 'would be IS NULL using GUID
' Build the TreeView list with supervisor and employees
Do Until rst.NoMatch
' Extract employee_name.
strText = rst![First] & " " & rst![Last]
' Add a root level node to the tree for the parent process
Set nodCurrent = objTree.Nodes.Add(, , "a" & rst!PersonalID, strText,
Int(rst!Image))
' Use a placeholder to save this place in the recordset.
bk = rst.Bookmark
' Run a recursive procedure to add all the child nodes für
AddChildren nodCurrent, rst
' Return to your placeholder.
rst.Bookmark = bk
' Find the next supervisor.
rst.FindNext "[ReportsToID] = 0"
Loop
End Sub
Sub AddChildrenA(nodboss As node, rst As DAO.Recordset)
Dim nodCurrent As node
Dim objTree As TreeView, strText As String, bk As String
Dim db As DAO.Database
'Dim rst As DAO.Recordset
' Create a reference to the TreeView control.
Set objTree = Form_Employee!xTree.Object
' Find the first employee who reports to the supervisor for this
' node.
rst.FindFirst "[ReportsToID] =" & Mid(nodboss.Key, 2)
' Build the list of employees who report to this supervisor.
Do Until rst.NoMatch
' Extract the employee's name.
strText = rst![First] & " " & rst![Last]
' Add as a child node to the tree.
Set nodCurrent = objTree.Nodes.Add(nodboss, tvwChild, "a" &
rst!PersonalID, strText, Int(rst!Image))
' Save your place in the recordset.
bk = rst.Bookmark
' Add any employees for whom the current node is a supervisor.
AddChildren nodCurrent, rst
' Return to your place in the recordset and continue to search.
rst.Bookmark = bk
' Find the next employee who reports to this supervisor.
rst.FindNext "[ReportsToID]=" & Mid(nodboss.Key, 2)
Loop
End Sub