|
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.Requery 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.Requery). 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!CategoryControl.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!CategoryControl.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
|
|
|
|