1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| Private Sub Form_Load()
Const strTableQueryName = "ZLT Tools"
Dim db As DAO.Database, rst As DAO.Recordset
Set db = CurrentDb
Set rst = db.OpenRecordset(strTableQueryName, dbOpenDynaset, dbReadOnly)
AddBranch rst:=rst, strPointerField:="Tool Type", strIDField:="N°", strTextField:="Part Number"
End Sub
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
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
rst.FindFirst strCriteria
Do Until rst.NoMatch
strText = rst(strTextField)
strKey = "a" & rst(strIDField)
If Not IsMissing(varReportToID) Then
Set nodCurrent = objTree.Nodes.Add(nodParent, tvwChild, strKey, strText)
Else
Set nodCurrent = objTree.Nodes.Add(, , strKey, strText)
End If
bk = rst.Bookmark
AddBranch rst, strPointerField, strIDField, strTextField, rst(strIDField)
rst.Bookmark = bk
rst.FindNext strCriteria
Loop
exitAddBranch:
Exit Sub
errAddBranch:
MsgBox "Can't add child: " & Err.Description, vbCritical, "AddBranch Error:"
Resume exitAddBranch
End Sub |
Partager