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

TreeView Behavior: "The object invoked has disconnected from it's clients"?

P: n/a
I've got a routine that loads a tree control.

Works a-ok the first time around, then bombs the second. Works the
third, bombs on the fourth....i.e. it works every other time it is
invoked.

Error# always the same: -2214 741 7848, but the message varies between
"Method 'Add' of object INodes failed." and "The object invoked has
disconnected from it's clients." The first one is more common.

Must be something to do with the state of the control. But, for the
life of me, I cannot see anything in the code...but it must be there,
right?

Anybody been here before?

The code: (Google's word wrapping seems to have had it's way with
it...if you're serious about trying to read it, flip an eMail to
20******@FatBelly.com and I'll ship you an un-wrapped version in a
..txt attachment)
-----------------------------------------------------
Public Function Load_ElementTree(ByVal theCheckBoxSwitch As Boolean,
ByRef theTree As Control, ByRef theElementRS As DAO.Recordset,
Optional ByVal theNameFilter As String) As Long
1000 debugStackPush mModuleName & ": Load_ElementTree"
1001 On Error GoTo Load_ElementTree_err

' PURPOSE: To load a tree with up to six heirarchy levels
' ACCEPTS: - Switch telling whether-or-not to show a checkbox on
each node
' - Pointer to the tree TB loaded
' - Pointer to DAO recordset containing elements TB
loaded, which must contain the following fields:
' > ElementID: PK to the table that contains detail
informatin for the current entry
' > NameLev1: The name TB used in heirarchy level 1
' > NameLev2...6: As above, but for heirarchy levels 2
through 6
' - Optional string containing a name fragment to filter
the tree for
' RETURNS: Number of fields loaded
'
' NOTES: 1) We only load ACTIVE elements. As far as the user is
concerned, anything with IsDeleted=True
' has fallen off the edge of the earth.
' 2) We're wimping out on the max levels issue. Instead
of writing a loop that concocts sql for
' deeper and deeper levels, we're just in-line coding
for six.
1002 Dim thisDB As DAO.Database
Dim collectionRS As DAO.Recordset
Dim myQuery As DAO.QueryDef
Dim curNode As Node

Dim i As Integer
Dim curNodeText As String
Dim curParentKey As String

Dim prvNameLev1 As String
Dim prvNameLev2 As String
Dim prvNameLev3 As String
Dim prvNameLev4 As String
Dim prvNameLev5 As String
Dim prvNameLev6 As String

Dim curNodeKeyLev1 As String
Dim curNodeKeyLev2 As String
Dim curNodeKeyLev3 As String
Dim curNodeKeyLev4 As String
Dim curNodeKeyLev5 As String
Dim curNodeKeyLev6 As String

Dim loadCount As Long 'number of items actually loaded

Dim itemCount As Long 'strictly for debugging
Dim curNameLev1 As String
Dim curNameLev2 As String
Dim curNameLev3 As String
Dim curNameLev4 As String
Dim curNameLev5 As String
Dim curNameLev6 As String
Dim curElementID As Long

Dim wantRecord As Boolean

1003 DoCmd.Hourglass True
1004 StatusSet "Loading elements..."

1010 With theTree
1011 .Visible = False
1012 .Nodes.Clear

1013 .Checkboxes = theCheckBoxSwitch
1014 .Indentation = 0
1015 .LineStyle = 1
1016 .Scroll = True
1017 .Sorted = True
1018 .Style = 6
1019 End With

1020 Set thisDB = CurDB()

1040 With theElementRS
1050 Do Until .EOF = True
1051 itemCount = itemCount + 1
1052 curNameLev1 = !NameLev1
1053 curNameLev2 = !NameLev2
1054 curNameLev3 = !NameLev3
1055 curNameLev4 = !NameLev4
1056 curNameLev5 = !NameLev5
1057 curNameLev6 = !NameLev6
1059 curElementID = !ElementID

1060 If Len(theNameFilter & "") > 0 Then
1061 If InStr(1, !NameLev1, theNameFilter) > 0 Then
1062 wantRecord = True
1063 Else
1064 wantRecord = False
1065 End If
1066 Else
2067 wantRecord = True
2069 End If

1070 If wantRecord = True Then
1079 loadCount = loadCount + 1
1100 If !NameLev1 <> prvNameLev1 Then
1101 prvNameLev1 = !NameLev1
1102 curNodeKeyLev1 = gTreeKeyDelimiter & CStr(!ElementID)
& gTreeKeyDelimiter & "1"
1103 curNodeText = !NameLev1
1109 Set curNode = theTree.Nodes.Add(, , curNodeKeyLev1,
curNodeText)
1110 prvNameLev2 = "" 'Neccessary to
handle situations where the same field name appears in different
consecutive tables
1111 prvNameLev3 = ""
1112 prvNameLev4 = ""
1113 prvNameLev5 = ""
1119 prvNameLev6 = ""
1199 End If

1200 If !NameLev2 <> prvNameLev2 Then
1201 prvNameLev2 = !NameLev2
1202 If Len(!NameLev2 & "") > 0 Then
1203 curNodeKeyLev2 = gTreeKeyDelimiter &
CStr(!ElementID) & gTreeKeyDelimiter & "2"
1204 curNodeText = !NameLev2
1205 Set curNode = theTree.Nodes.Add(curNodeKeyLev1,
tvwChild, curNodeKeyLev2, curNodeText)
1209 End If
1210 prvNameLev3 = ""
1211 prvNameLev4 = ""
1212 prvNameLev5 = ""
1219 prvNameLev6 = ""
1299 End If

1300 If !NameLev3 <> prvNameLev3 Then
1301 prvNameLev3 = !NameLev3
1302 If Len(!NameLev3 & "") > 0 Then
1303 curNodeKeyLev3 = gTreeKeyDelimiter &
CStr(!ElementID) & gTreeKeyDelimiter & "3"
1304 curNodeText = !NameLev3
1305 Set curNode = theTree.Nodes.Add(curNodeKeyLev2,
tvwChild, curNodeKeyLev3, curNodeText)
1309 End If
1310 prvNameLev4 = ""
1311 prvNameLev5 = ""
1319 prvNameLev6 = ""
1399 End If

1400 If !NameLev4 <> prvNameLev4 Then
1401 prvNameLev4 = !NameLev4
1402 If Len(!NameLev4 & "") > 0 Then
1403 curNodeKeyLev4 = gTreeKeyDelimiter &
CStr(!ElementID) & gTreeKeyDelimiter & "4"
1404 curNodeText = !NameLev4
1405 Set curNode = theTree.Nodes.Add(curNodeKeyLev3,
tvwChild, curNodeKeyLev4, curNodeText)
1409 End If
1410 prvNameLev5 = ""
1411 prvNameLev6 = ""
1499 End If

1500 If !NameLev5 <> prvNameLev5 Then
1501 prvNameLev5 = !NameLev5
1502 If Len(!NameLev5 & "") > 0 Then
1503 curNodeKeyLev5 = gTreeKeyDelimiter &
CStr(!ElementID) & gTreeKeyDelimiter & "5"
1504 curNodeText = !NameLev5
1505 Set curNode = theTree.Nodes.Add(curNodeKeyLev4,
tvwChild, curNodeKeyLev5, curNodeText)
1509 End If
1510 prvNameLev6 = ""
1599 End If

1600 If !NameLev6 <> prvNameLev6 Then
1601 prvNameLev6 = !NameLev6
1602 If Len(!NameLev6 & "") > 0 Then
1603 curNodeKeyLev6 = gTreeKeyDelimiter &
CStr(!ElementID) & gTreeKeyDelimiter & "6"
1604 curNodeText = !NameLev6
1605 Set curNode = theTree.Nodes.Add(curNodeKeyLev5,
tvwChild, curNodeKeyLev6, curNodeText)
1612 End If
1639 End If

1900 curNode.Expanded = False
1901 End If
1902 .MoveNext
1903 Loop
1909 End With

1996 theTree.Visible = True
1997 Load_ElementTree = loadCount
1998 StatusSet ""
1999 DoCmd.Hourglass False

Load_ElementTree_xit:
debugStackPop
On Error Resume Next
Set curNode = Nothing
Set myQuery = Nothing
collectionRS.Close
Set collectionRS = Nothing
Set thisDB = Nothing
Exit Function

Load_ElementTree_err:
bugAlert True, "ItemCount=" & Format$(itemCount, "0") & ",
NameLev1='" & curNameLev1 & "', NameLev2='" & curNameLev2 & "',
NameLev3='" & curNameLev3 & "', NameLev4='" & curNameLev4 & "',
NameLev5='" & curNameLev5 & "', NameLev6='" & curNameLev6 & "',
ElementID=" & Format$(curElementID, "0") & "."
Resume Load_ElementTree_xit
End Function
-------------------------------------
Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
> The code:

Trying to isolate the problem, I created a new from and put a new 6.0
TreeView control on it.

Same error from this code on every other attempt to load it:
-----------------------------------------------------
Private Sub cmdLoad_Click()

With treTest
.Visible = False
.Nodes.Clear
.Nodes.Add , , "!1!", "1"
.Visible = True
End With

End Sub
-----------------------------------------------------

Then I commented out the .Visible=False line and it worked.

viz:
-----------------------------------------------------
Private Sub cmdLoad_Click()

With treTest
' .Visible = False
.Nodes.Clear
.Nodes.Add , , "!1!", "1"
.Visible = True
End With

End Sub
-----------------------------------------------------

This seems like a major issue performance-wise. When the control is
loaded with 500+ items, it happens in the blink of an eye if it is
made invisible first...but takes way too long if it's visible while
being loaded.

Can anybody think of a workaround?
Nov 13 '05 #2

P: n/a
RE/
This seems like a major issue performance-wise. When the control is
loaded with 500+ items,


Looks like the preferred way is DoCmd.Echo False instead of .Visible=False.

At least that's what I did and the performance returned (6 instead of 37 seconds
to load...) but the mystery abend didn't.
--
PeteCresswell
Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.