Microsoft
Software
Hardware
Network
Question : refreshing tree view
G morning,
I have a form call frmRepository with a treeview on it named "CategoryControl". I am using a form call frmAddCategory to add a category to the treeview via the following code:
----
Private Sub cmdSaveCategory_Click()
Dim db As DAO.Database
Dim rsCats As DAO.Recordset
Set db = CurrentDb
Set rsCats = db.OpenRecordset _
("select * from tblCategory order by chrCategoryName", dbOpenDynaset)
With rsCats
.AddNew
!chrCategoryName = txtCategoryName.Value
.Update
.Close
Set db = Nothing
Set rsCats = Nothing
End With
Forms!frmRepository.Requer
y
DoCmd.Close
End Sub
-----
This form opens from the click event of frmRepository. Problem here is I cant seem to refresh the data in the treeview to reflect the new category added (ie: forms!frmRepository.Requer
y). The treeview is loaded from tables via DAO on the form load event. Thought a requery or refresh would work but it does not. Closing the frmRepository oand reopeing displays the changes.
Anyone have any ideas? I am sure there is a simple solution here, just dont see it
thanks
syntnx
Answer : refreshing tree view
you only need one line... because the when you are essentially requerying the treeview, it is just trying to add new stuff, it is running into conflicts with whats already there... make this change...
With Forms!frmRepository!Catego
ryControl.
Nodes
While rsCats.EOF = False
.Add , , "a" & rsCats!intCategoryID, rsCats!chrCategoryName, 1
Set rsSubCats = db.OpenRecordset _
("select * from tblSubCategory where intCategoryID_child=" & _
rsCats!intCategoryID & " order by chrSubCategoryName", dbOpenDynaset)
While rsSubCats.EOF = False
CHANGE TO
With Forms!frmRepository!Catego
ryControl.
Nodes
.Clear
While rsCats.EOF = False
.Add , , "a" & rsCats!intCategoryID, rsCats!chrCategoryName, 1
Set rsSubCats = db.OpenRecordset _
("select * from tblSubCategory where intCategoryID_child=" & _
rsCats!intCategoryID & " order by chrSubCategoryName", dbOpenDynaset)
While rsSubCats.EOF = False
Note the .Clear on the second line- that will remove all existing Nodes, allowing a "requery" to be possible without repeating any keys...
Mike
Random Solutions
ASP.NET to Sharepoint: master page, types, and other problems
Excel Conditional Column Input
Problem with DoCmd.RunSQL "INSERT INTO " and memo fields
Scandisk: (XXXXXXXX.. of XXXXXXX.. USN bytes processed)
Problem with error 2465
Working with recordsets
STOP: 0x00000007B (0xF7B44528, 0xC0000034, 0x00000000, 0x00000000)
Windows 98 Splash Screen (logo) freezes during bootup
Modifying tableadapter parameters
Exchange 2003 Cluster, Event ID: 1080 occurs every three seconds