ClaraBarton
Registered User.
- Local time
- Today, 15:42
- Joined
- Oct 14, 2019
- Messages
- 735
@MajP
Because I'm looking for an address and the nodetext is very lengthy, I changed the NodeText to NodeLevel. That's not right either.
What I'm looking for, and I think it's in E2E... sort of
Each item has a DocNo that will be the ending number.
But the LOPath of the locations should be:
Top Drawer - 1
Numeric - 1 - 1
Religion - 1 - 2
On down to
Bottom Drawer - 3
Computer - 3 - 1
Excel - 3 - 1 - 3
Definitely outside my skillset.
Because I'm looking for an address and the nodetext is very lengthy, I changed the NodeText to NodeLevel. That's not right either.
What I'm looking for, and I think it's in E2E... sort of
Each item has a DocNo that will be the ending number.
But the LOPath of the locations should be:
Top Drawer - 1
Numeric - 1 - 1
Religion - 1 - 2
On down to
Bottom Drawer - 3
Computer - 3 - 1
Excel - 3 - 1 - 3
Definitely outside my skillset.
Code:
Public Sub RecurseIGTree(Optional ParentID As Variant = Null, Optional RS As DAO.Recordset = Nothing, Optional Path As String = "")
'This assigns the levels and tree sort
'if the top level parent ID is null do not pass in anything
Dim strCriteria As String
Dim bk As String
Dim PathIn As String
If RS Is Nothing Then
'On the first call to the method open a recordset then pass it in recursion
Dim strSql As String
strSql = "qryUnion"
Set RS = CurrentDb.OpenRecordset(strSql, dbOpenDynaset)
If IsNull(ParentID) Then
'nothing passed in at start
strCriteria = "ParentID = 'LO'"
RS.FindFirst (strCriteria)
If RS.NoMatch Then
MsgBox "There is no record with a Parent ID of " & ParentID
Exit Sub
End If
End If
Else
'all other calls you pass in the parentID
strCriteria = "ParentID = '" & ParentID & "'"
End If
Debug.Print strCriteria
RS.FindFirst (strCriteria)
PathIn = Path
Do Until RS.NoMatch
bk = RS.Bookmark
If RS!ParentID = "LO" Then Path = ""
'reset the path when you come back to a top level node
'This reset has to occur in the loop to account for coming back to root level
If RS!ParentID = "LO" Then Path = ""
'To keep you from adding to the path within a level
Path = PathIn
If Path = "" Then
'Items need a path
Path = " > " & RS!NodeLevel
Else
If RS!Identifier = "LO" Then Path = Path & " > " & RS!NodeLevel
End If
Debug.Print Path
If RS!Identifier = "IT" Then Debug.Print RS!nodeText
If RS!Identifier = "LO" Then
strSql = "Update tblLocations set LOPath = '" & Path & "' where LocID = " & Replace(RS!ID, RS!Identifier, "")
Debug.Print strSql
CurrentDb.Execute strSql
Else
strSql = "Update tblItems set ITPath = '" & Path & "' where ItemID = " & Replace(RS!ID, RS!Identifier, "")
Debug.Print strSql
CurrentDb.Execute strSql
End If
' Debug.Print
'The current Record is passed as the parent.
RecurseIGTree RS!ID, RS, Path
RS.Bookmark = bk
RS.FindNext strCriteria
Loop
End Sub