Treview - Move Data into an Active Treview Control

I want to take a tree view control on the left of a form and a data sheet on the right.  I would like to move data from the right form and put it under a specific heading on the tree view.  One value from the right could be under multiple headings on the tree.

So the perfect scenario would be for the user to highlight a value on the tree and highlight a value on the right form, push a button - and the value is still on the right but also under the heading on the Left.

Any help is greatly appreciated.
LJG

Note: The attached Treeview is Reader's Companion.mdb by Helen Feddema



   
TreeView-To-ExpEx2.jpg
LVL 2
LJGAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NorieVBA ExpertCommented:
Is there meant to be a file attached or do you just mean the image?

0
LJGAuthor Commented:
Sorry - Just the image
0
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Do you fully understand how the Treeview is populated? It's just a "tree view" of your related tables, and so all the Child Items of Greg Bear are included under  that "root" item, and so on.

So if you wish to move an item from the Greg Bear root to the Kage Baker root, you'd have to move that data IN THE TABLES and then repopulate the treeview - assuming, of course, that you want these changes to "stick" when you close down this form.

You can do that in several ways, but of course you'd have to have the info necessary to make those changes - for example, you'd need the PrimaryKey value for Kage Baker. Once you do this, you'd just run a simple UPDATE query, and then refresh your treeview.

If you're talking about something else, then please explain further.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

NorieVBA ExpertCommented:
You can add items, delete items, drag and drop items in a treeview but the changes you make won't be reflected in the source data.

So you would need to write the data back to the table either when the change is made or when you close the form.

0
LJGAuthor Commented:
Thanks for the info

>> My Basic Question:
 I want to do a simple add of "Merry Christmas..." under "Bisson, Terry" on the treeview without repopulating the treeview.


>> Assumed Facts of My Process:
    1) I have a table of "tbl_Customers" (Anderson, Atwood, Baker ....) (I know in Helen's example they are authors)
    2) I have a table that is connected to customers (tbl_Purchases) that contains all the books the customer bought.
    3) By working with tbl_Customers and tbl_Purchases, I fill in the treeview control on the form.  Hence I get that Stephen Booth bought "Black Dog: A...)

>>The Process I see
    1) The user clicks on "Bisson, Terry" in the treeview control and then clicks on "Merry Christmas..." on the right form and then clicks a button "Add"
    2) At that point I call a stored procedure that adds"Merry Christmas..." and "Bisson, Terry" to tbl_Purchases
    3) I want to do a simple add of "Merry Christmas..." under "Bisson, Terry" on the treeview without repopulating the treeview.  The treeview is not directly hooked to the tables so I'm  just am looking for a simple way to add it to the treeview.



         
 
0
NorieVBA ExpertCommented:
It's pretty easy to add to the treeview.

This will add a child to the selected node.
Set selNode = tvwBooks.Object.SelectedItem
    
tvwBooks.Nodes.Add selNode, tvwChild, "Xmas",  "Merry Christmas"

Open in new window

Bad example I know but it kind of show's how it's done.

To update the tables you would need to add a new record to tblBooks.

Then using that ID and the author ID you need to add a record to tblBookAuthors.

You can get the author ID from the key of the author node.

After all that's done succesfully both table and treeview should be updated.

The next time the treeview is populated from the table it should reflect the change(s) made.

The whole code might look something like this.
  Dim selNode As Node
    Dim AllNodes As Nodes
    Dim NewBookID As Long
    Dim AutID As Long

    Set selNode = tvwBooks.Object.SelectedItem


    AutID = Val(Mid(selNode.Key, 9))

    tvwBooks.Nodes.Add selNode, tvwChild, "Xmas", "Merry Christmas"

    CurrentDb.Execute "INSERT INTO tblBooks(Title) VALUES('Merry Christmas')"


    NewBookID = DMax("BookID", "tblBooks")


    CurrentDb.Execute "INSERT INTO tblBookAuthors (AuthorID, BookID) VALUES (" & AutID & "," & NewBookID & ")"

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LJGAuthor Commented:
imnorie

Thanks so much for the answer.  You have the points, but if you have time could you give me an explanation of the following line.

tvwBooks.Nodes.Add selNode, tvwChild, "Xmas", "Merry Christmas"

>>> I undersstand
    tvwBooks = Treeview Name
    Nodes = Nodes are what we see in the tree and we want to add one
    Add = we want to add a node
     "Merry Christmas" = The Value I want to add

>>> I don't undersstand
     selNode = ??? Is this saying selected node???
     tvwChild = ??? Is this saying we are adding a child to the selected node???
      "Xmas" = ??????

Thanks again for all the help
LJG
0
NorieVBA ExpertCommented:
selNode is a variable that is a reference to the selected node in the treeview.

Using tvwChild is to add the new child node under the selected node.

'Xmas' is really just arbitrary - couldn't think of anything else to use at the time.

When I think about it using the ID of the new book would probably be a better option.

To do that the order would need to be changed a little, something like this

1 Add book to table using SQL.

2 Get new book's ID.

3 Add new node, with book's ID as the Key and the book title as Text.

The code is based on the example database so there's probably a lot of things that would need changing when
implementing something like this in your own database.
0
LJGAuthor Commented:
Thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.