I have a TreeView control on a form in an Access ADP.
It shows Inventory and Categories below it.
I have a button that opens a form to add a Category
After Adding the Category I would like to refresh the TreeView so it shows
the newly added Category.
Right now, the only way to see the new Category is to close the form and
repoen it.
I tried Me.axTreeView.Requery and nothing happens.
I also tried to call the function that populates the TreeView when the form
opens and I get an error "key is not unique in collection"
Any help is appreciated - AB
code to populate TreeView is below...
------------------------------
Private Sub Form_Load()
Call RefreshTreeView
End Sub
---------------------------------
Public Sub RefreshTreeView()
Dim CN As ADODB.Connection, rs As ADODB.Recordset
Set CN = CurrentProject.Connection
Set rs = New ADODB.Recordset
rs.Open "tblCategory", CN, adOpenForwardOnly
Do Until rs.EOF
If (rs!ParentID = 0) Then
Me!axTreeview.Nodes.Add , , "o" & rs!ID, rs!Name
End If
rs.MoveNext
Loop
rs.Close
Dim foundSubCateogory As Boolean
foundSubCategory = True
Do Until foundSubCategory = False
rs.Open "tblCategory", CN, adOpenForwardOnly
foundSubCategory = False
Do Until rs.EOF
On Error Resume Next
Me!axTreeview.Nodes.Add "o" & rs!ParentID, tvwChild, "o" & rs!
ID, _
rs!Name
Select Case Err
' If error is because nothing is selected in TreeView.
Case 35601
Case 35602
Case 0
'do nothing
foundSubCategory = True
Case Else
MsgBox "Error: " & Err.Number & vbCr & Err.Description
End Select
rs.MoveNext
Loop
rs.Close
Loop
Set rs = Nothing
Set CN = Nothing
End Sub
Alex Dybenko - 03 Feb 2005 06:06 GMT
Hi,
i think you could try to clear nodes before refreshing TV, add at the
beginning of RefreshTreeView()
Me!axTreeview.Nodes.clear

Signature
Alex Dybenko (MVP)
http://Alex.Dybenko.com
http://www.PointLtd.com
>I have a TreeView control on a form in an Access ADP.
>
[quoted text clipped - 76 lines]
>
> End Sub