Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / ActiveX Controls / February 2005

Tip: Looking for answers? Try searching our database.

Refresh a TreeView Control after Adding Record

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
AB - 02 Feb 2005 17:12 GMT
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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.