I have tree view which shows categories and sub of subcategories. Which I would name it as "Product groups"
- Main form name (having tree view of product group) : ProductGroupF
- Subform name : ProductDetailSubF (bound to query "ProductDetailQ")
Two tables:
1st table -- "ProductGroupT" looks like as below
as can be seen subgroup is created, by bringing groupID into parentID
2) 2nd table -- "ProductDetailT" Looks like as below
in this table product group ID (not parent ID) is inserted, while creating a product detail.
ProductDetailQ is query combining above two
Product groups as tree on form look like as below
In this it can be seen "Groceries" is one of the main Group, then Rice + Flour are sub at level 2, and so on...
Main form has an "Unbound control" named as "txtGroupID", by click on any of tree Nod (groups), this field is populated with ID number via vba.
this "txtGroupID" is acting as master field on main form, which is linked with subform child field. If this "txtGroupID" value is "4" which is Men in above group table so all products from Product detail table matching to "4" are filtered.
Because main form and subform have Master and child fields linked to filter exact match of IDs, therefore now I am not using this relationship. Rather I am using Sql select statement as below.
Reason: As can be seen in product group table "Product Group" has Group ID: 1, while parent ID: 0, which are not used in any product. So by clicking on top of tree "Product Group", it does not show any product. So subform is empty.
While I wanted to have all products in this case. Therefore sql select statement with condtion if greater than 1, is working fine to deliver this.
Now my question:
in above tree Groceries, rice, Flour have no product but their further subs eg, Basmati rice etc have product. My code does not show all products under Groceries while I want it should show. By click on Groceries, all products related to groceries should appear.
Similarly if we click on "Flour" it should show all types of Flour, and then further filtering by clicking on it sub levles.
I hope I am able to make you understand what I mean. below is my code on Nod click.
On main form load "to show all records, product detail" by default --- on load event
Main form has two unbound controls (1. txtGroupID 2. txtParentID ), which are populated by nod click
on Nod click event
Below I made illustration to show, how ProductGroup ID, is acting as ProdParentGroupID in next (down) sub level and so on.
Thanks for reading this. How can I modify my above code on NodeClick event.
- Main form name (having tree view of product group) : ProductGroupF
- Subform name : ProductDetailSubF (bound to query "ProductDetailQ")
Two tables:
1st table -- "ProductGroupT" looks like as below
as can be seen subgroup is created, by bringing groupID into parentID
2) 2nd table -- "ProductDetailT" Looks like as below
in this table product group ID (not parent ID) is inserted, while creating a product detail.
ProductDetailQ is query combining above two
Product groups as tree on form look like as below
In this it can be seen "Groceries" is one of the main Group, then Rice + Flour are sub at level 2, and so on...
Main form has an "Unbound control" named as "txtGroupID", by click on any of tree Nod (groups), this field is populated with ID number via vba.
this "txtGroupID" is acting as master field on main form, which is linked with subform child field. If this "txtGroupID" value is "4" which is Men in above group table so all products from Product detail table matching to "4" are filtered.
Because main form and subform have Master and child fields linked to filter exact match of IDs, therefore now I am not using this relationship. Rather I am using Sql select statement as below.
Reason: As can be seen in product group table "Product Group" has Group ID: 1, while parent ID: 0, which are not used in any product. So by clicking on top of tree "Product Group", it does not show any product. So subform is empty.
While I wanted to have all products in this case. Therefore sql select statement with condtion if greater than 1, is working fine to deliver this.
Now my question:
in above tree Groceries, rice, Flour have no product but their further subs eg, Basmati rice etc have product. My code does not show all products under Groceries while I want it should show. By click on Groceries, all products related to groceries should appear.
Similarly if we click on "Flour" it should show all types of Flour, and then further filtering by clicking on it sub levles.
I hope I am able to make you understand what I mean. below is my code on Nod click.
On main form load "to show all records, product detail" by default --- on load event
Code:
Forms.ProductGroupF.ProductDetailSubF.Form.RecordSource = "SELECT * FROM ProductDetailQ "
Main form has two unbound controls (1. txtGroupID 2. txtParentID ), which are populated by nod click
on Nod click event
Code:
Private Sub CategoriesInTreeView_NodeClick(ByVal Node As Object)
Dim objName As String, nodOn As MSComctlLib.Node
Dim PID As Integer
'This applies only to the Node having child Nodes
If Node.Expanded = False Then
Node.Expanded = True
Else
Node.Expanded = False
End If
' this is for bringing the ID on the Main form, this ID field which is linked with subform as Master field
Me.txtGroupID = Mid(Node.Key, 2)
'If 1st parent category is selected, whose ID is Zero, then bring all results
If Me.txtParentID.Value = 0 Then
Forms.ProductGroupF.ProductDetailSubF.Form.RecordSource = "SELECT * FROM ProductDetailQ "
Else
'If ID is greater than zero, then brings results as per Nod Click (based on their ID)
If Me.txtParentID.Value > 0 Then
Forms.ProductGroupF.ProductDetailSubF.Form.RecordSource = "SELECT * FROM ProductDetailQ " & _
"WHERE (ProductDetailQ.[ID_ProductGroup])= " & Me.txtGroupID.Value
End If
End If
' to find the parent ID of category, by click on NOD
PID = DLookup("[ID_ProdParentGroup]", "[ProductGroupT]", "[ID_ProductGroup] =" & Me.txtGroupID.Value)
Me.txtParentID.Value = PID
End Sub
Below I made illustration to show, how ProductGroup ID, is acting as ProdParentGroupID in next (down) sub level and so on.
Thanks for reading this. How can I modify my above code on NodeClick event.
Attachments
Last edited: