Results 1 to 12 of 12
  1. #1
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Treeview (A2000 SR1)

    I'm just getting started playing about with a treeview control.

    My attachment shows staff and their relevant department.

    Is it possible to have the subform to the right of my TView to match the surname on change.

    Please see attachment

    Thanks
    Dave
    Attached Files Attached Files

  2. #2
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Toronto, Ontario, Canada
    Posts
    1,139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Treeview (A2000 SR1)

    Dave,

    It's was pretty tough to figure out with your data structure. There is no real logical link between the data in the treeview and the data in the subform.

    Having said that, here is a way that you can do it.

    On frmBasicDAO add a text box called txtLink.

    In the properties of the Subform, Set the
    Link Child Field to Surname
    Link Master Field = txtLink

    In the NodeClick event of the Treeview add these lines:
    <pre>If Right$(Node.Key, 2) = "L2" Then
    txtLink = Mid$(Node.Text, InStr(Node.Text, " ") + 1)
    End If</pre>


    That will work unless you get anyone with a first name with a space in it, like "Jean Paul", "Mary Ann"....

    Just as an aside, you should look at normalizing you data. You have too much redundant data in the tables
    --
    Bryan Carbonnell - Toronto <img src=/S/flags/Ontario.gif border=0 alt=Ontario width=30 height=18> <img src=/S/flags/Canada.gif border=0 alt=Canada width=30 height=18>
    Unfortunately common sense isn't so common!!
    Visit my website for useful Word, Excel and Access code, templates and Add-Ins

  3. #3
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Treeview (A2000 SR1)

    Hello Bryan.
    Firstly thanks.
    One thing, where is the NodeClick event ?

    I understand with the data normalisation etc, but this is only a demo i'm messing with so doesn't really matter.

    Once I've got the hang of it I can then progress and build it correctly.

    Thanks

    Dave

  4. #4
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Toronto, Ontario, Canada
    Posts
    1,139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Treeview (A2000 SR1)

    Dave,

    Open the from in design mode, press F11, that will take you into the VBE.

    From there, open the Form_frmBasicDAO code module. In the Project Explorer (CTRL+R, if it's not open) Expand Microsoft Access Class Object and Double Click on Form_frmBasicDAO. That will open the code module.

    From the Object Drop Down, at the top of the code window, select tvwTest. From the Procedure Cdrop down, select NodeClick. That will create the NodeClick event Stub for you.

    Copy and paste the code that I posted earlier in there.

    That'll do it.
    --
    Bryan Carbonnell - Toronto <img src=/S/flags/Ontario.gif border=0 alt=Ontario width=30 height=18> <img src=/S/flags/Canada.gif border=0 alt=Canada width=30 height=18>
    Unfortunately common sense isn't so common!!
    Visit my website for useful Word, Excel and Access code, templates and Add-Ins

  5. #5
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Treeview (A2000 SR1)

    Cheers Bryan

    It works just fine.

    Dave

  6. #6
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Treeview (A2000 SR1)

    Another question.

    How would I go about adding sub nodes ?

    Dave

  7. #7
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Toronto, Ontario, Canada
    Posts
    1,139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Treeview (A2000 SR1)

    Dave,

    <pre>tvwTest.Object.Nodes.Add "KeyOfParent", tvwChild, "KeyOfChildNode", "TextToSee"</pre>


    Will add a sub node (child node).
    --
    Bryan Carbonnell - Toronto <img src=/S/flags/Ontario.gif border=0 alt=Ontario width=30 height=18> <img src=/S/flags/Canada.gif border=0 alt=Canada width=30 height=18>
    Unfortunately common sense isn't so common!!
    Visit my website for useful Word, Excel and Access code, templates and Add-Ins

  8. #8
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Treeview (A2000 SR1)

    Sorry to seem a little daft Bryan, Thanks for your input, but.

    I don't understand where to put the code.

    Dave

  9. #9
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Toronto, Ontario, Canada
    Posts
    1,139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Treeview (A2000 SR1)

    Well It depends on how you want to add the child node?

    Do you want to add the Child node added when you fill the TreeView? When you click a button? after some time frame?

    Where you put the code is all dependant on how and when you want to add the child node.
    --
    Bryan Carbonnell - Toronto <img src=/S/flags/Ontario.gif border=0 alt=Ontario width=30 height=18> <img src=/S/flags/Canada.gif border=0 alt=Canada width=30 height=18>
    Unfortunately common sense isn't so common!!
    Visit my website for useful Word, Excel and Access code, templates and Add-Ins

  10. #10
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Treeview (A2000 SR1)

    The tree shows two levels, each representing data from a particular table.

    I will have to create another table for the extra data Lets say tblWhatever, its how to create another level of nodes relating to the other tables.

    You see, as I mentioned earlier, I'm just trying to get the feeling for the treeview at the moment.
    My data and how I apply it, is subject to gaining enough knowledge.
    So explanations are really helpful at this time.

    Regards

    Dave

  11. #11
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Toronto, Ontario, Canada
    Posts
    1,139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Treeview (A2000 SR1)

    I think the easiest way to explain it is to actually send a demo, so here you go.

    The code is really simple, as you will see.

    The only thing to remember is that each level (with the exception of the first level) needs to be related somehow to the Parent level (the level above it)

    In the sample, if you open the relationship window, you will see how the 3 tables relate to each other.

    Let me know if this helps, or if you have any questions about it.
    Attached Files Attached Files
    --
    Bryan Carbonnell - Toronto <img src=/S/flags/Ontario.gif border=0 alt=Ontario width=30 height=18> <img src=/S/flags/Canada.gif border=0 alt=Canada width=30 height=18>
    Unfortunately common sense isn't so common!!
    Visit my website for useful Word, Excel and Access code, templates and Add-Ins

  12. #12
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Treeview (A2000 SR1)

    Thanks Bryan.

    Excellent demo. This gives enough to start playing.

    Regards
    Dave

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •