By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,139 Members | 1,247 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,139 IT Pros & Developers. It's quick & easy.

MPT Tree for Access

P: n/a
Mark Johnson wrote in:
http://groups.google.com/groups?hl=e...u7n3%404ax.com
but, for example, with the Celko version, if you don't
include the conditionals that I included in the examples I posted then
you could add multiple nodes at the highest level - only implying a
superior root node, which doesn't exist.


Mark, where exactly in your code are the conditionals that need to be
removed for the case mentioned above? - multiple nodes at the highest
level. Some of us need these things spelled out. Thanks.

Jacob

Your Code:

Private Const MPT2_SubLast = 1
Private Const MPT2_SubFirst = 2
Private Const MPT2_InsertAfter = 3
Private Const MPT2_InsertBefore = 4
' Called by a cover function which supplies the name for new node,
' the name of the reference node, and the insertion mode
Private Sub sMPTTadd(strNew As String, strRef As String, ByVal
bytWhere As Byte)

Dim varRead As Variant, lngLftPivot As Long, lngRgtPivot As Long,
lngNewLft As Long

varRead = DLookup("lngR", "mpttTest", "txCategory='" & strRef &
"'")
If IsNull(varRead) Then
lngRgtPivot = IIf(fGetThisDB.OpenRecordset("SELECT Count(*)
FROM mpttTest")(0) > 0, DLookup("lngR", "mpttTest", "lngL=1"), 1)
bytWhere = MPT2_SubLast
Else
lngRgtPivot = varRead
varRead = DLookup("lngL", "mpttTest", "txCategory='" & strRef
& "'")
If varRead = 1 Then bytWhere = MPT2_SubLast
End If

lngLftPivot = lngRgtPivot
lngNewLft = lngRgtPivot

Select Case bytWhere
Case MPT2_SubLast
lngRgtPivot = lngRgtPivot - 1
Case MPT2_SubFirst
lngLftPivot = varRead
lngRgtPivot = lngLftPivot
lngNewLft = lngLftPivot + 1
Case MPT2_InsertBefore
lngNewLft = varRead
lngLftPivot = lngNewLft - 1
lngRgtPivot = lngLftPivot
Case MPT2_InsertAfter
lngNewLft = lngNewLft + 1
End Select

fGetThisDB.Execute "UPDATE mpttTest SET lngL = iif(lngL > " &
lngLftPivot & ", lngL + 2, lngL)," & _
" lngR = iif(lngR > " &
lngRgtPivot & ", lngR + 2, lngR)"

fGetThisDB.Execute "INSERT INTO mpttTest (txCategory, lngL, lngR)
VALUES ('" & strNew & "'," & lngNewLft & "," & lngNewLft + 1 & ")"

End Sub
Nov 12 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.