Solved List view based on category tree view in ms access (1 Viewer)

Ihk

Member
Local time
Today, 09:26
Joined
Apr 7, 2020
Messages
280
Based on the articles (linked below), I created tree view of category.
I am trying to filter records in list view based on Nod selected, so far I have no success. Sample db is attached, if some one can help me out.
I want
1) Based on category selected - records in list view
2) if possible, want to give different colours and size to each Nod (category level).
I am new to this (Nod), not sure how can I identify category levels (nods).

In my sample db: I have form "Menu2withList2" has vba function on load for tree view. It also has list view function, but not called yet.
Thanks

Credit refrence:
tree view: Creating Access Menu with Tree View Control ~ LEARN MS-ACCESS TIPS AND TRICKS (msaccesstips.com)
List view: ListView Control with Ms-Access TreeView ~ LEARN MS-ACCESS TIPS AND TRICKS (msaccesstips.com)
On this list view has been nicely shown, but in the tree view is already expanded, I want other way around. As in my sample db.
 

Attachments

  • Menu with Tree List View.accdb
    3 MB · Views: 287

June7

AWF VIP
Local time
Yesterday, 23:26
Joined
Mar 9, 2014
Messages
5,466
Couldn't stop until I had it working. Lot of changes so am attaching modified file. Some highlights below.

Code in NodeClick event would call LoadListView procedure and pass value to filter the listview recordset.
Can extract category ID from Node.Key. LoadListView Mid(Node.Key, 2)
Shouldn't the listview recordset filter on ID_ParentCategory, not ID_Article?

What purpose will listview serve? Wonder if a listbox or subform would accomplish what you want.
LoadListView code was referencing objTreeview instead of objListview.
Needed to Set the listview object variable (this is not in the tutorial sample): Set objListview = Me.ListView0.Object
Variable Prfx should be Prefix and concatenate with ID_Article: strPKey = Prefix & CStr(rst!ID_Article)

Form Menu2withList2 NodeClick event does not trigger. Don't know why. The other forms with this event worked.

Built a Colors table and saved the ColorID into CategoryT table and included in recordset query.
Review http://www.cloford.com/resources/colours/500col.htm#:~:text=500+ Colours Colour Name , 12168959 34 more rows

I noticed some spelling errors in categories - are these real data or just for testing?
 

Attachments

  • Menu with Tree List View.accdb
    580 KB · Views: 284
Last edited:
  • Love
Reactions: Ihk

Ihk

Member
Local time
Today, 09:26
Joined
Apr 7, 2020
Messages
280
Couldn't stop until I had it working. Lot of changes so am attaching modified file. Some highlights below.

Code in NodeClick event would call LoadListView procedure and pass value to filter the listview recordset.
Can extract category ID from Node.Key. LoadListView Mid(Node.Key, 2)
Shouldn't the listview recordset filter on ID_ParentCategory, not ID_Article?

What purpose will listview serve? Wonder if a listbox or subform would accomplish what you want.
LoadListView code was referencing objTreeview instead of objListview.
Needed to Set the listview object variable (this is not in the tutorial sample): Set objListview = Me.ListView0.Object
Variable Prfx should be Prefix and concatenate with ID_Article: strPKey = Prefix & CStr(rst!ID_Article)

Form Menu2withList2 NodeClick event does not trigger. Don't know why. The other forms with this event worked.

Built a Colors table and saved the ColorID into CategoryT table and included in recordset query.
Review http://www.cloford.com/resources/colours/500col.htm#:~:text=500+ Colours Colour Name , 12168959 34 more rows

I noticed some spelling errors in categories - are these real data or just for testing?
1st of all, I am very grateful for your efforts and input as well as final solution. You tried and updated the post time to time. I am very much pleased.
Though being not from computer field, still have good knowledge & experience in access database, forms queries, modules. But I was totally new to tree view, list view. Spent more than a week daily fews hrs to read and understand about this. Not that much material was available. Got success to understand / make a tree view, but was stuck on list view linked to tree.
I got more than that what I was looking for. This colour management from table is really nice and new option for me. Yes there were spelling mistakes, because it was sample db for tree/listview only or the db where I was trying to get this solution.
Just an extra and for my knowledge question,
- is there way to get NOD (categories and sub categories etc) key or ID by message box., because i want to how is fetching results, how nods work.
- How can I directly search from listview under that category/subcategory, (As we do search from any lisbox based on a query).
Whenever if possible, please on a extra form (copy of form in above db), for my learning purpose. Many thanks.
 
Last edited:

June7

AWF VIP
Local time
Yesterday, 23:26
Joined
Mar 9, 2014
Messages
5,466
Where would you want a MsgBox?

MsgBox Node.Key
LoadListView Mid(Node.Key, 2)

As for using the listview item, I found this https://www.tek-tips.com/viewthread.cfm?qid=832679 and distilled it to the following.

Private Sub listView0_DblClick()
MsgBox Me.ListView0.SelectedItem.ListSubItems(1).Text
End Sub

Unfortunately, an index of 0 does not work so I cannot grab value from first column. If you need ID_Article value, modify code to build a 4th column in the listview with that field, then:
MsgBox Me.ListView0.SelectedItem.ListSubItems(3).Text

Instead of MsgBox, do whatever you want with the data. Sample in link shows applying filter to a form.
 
Last edited:
  • Like
Reactions: Ihk

Users who are viewing this thread

Top Bottom