Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need Treeview to display editable fields when child node clicked on

Status
Not open for further replies.

DonnaB

Programmer
Apr 23, 2001
34
0
0
AU
Hi,

I have created a treeview on a form, along with some fields from the database. The treeview is working as required (allowing nodes that are read from db to be opened and closed) however, I would like to be able to click on the lowest level node and display extra data (which is read from db) in the fields on the form.

When the form is started data is already populating the fields on the form, which is not what I want, as they should be blank until one of the lowest children nodes is clicked on.

I've discovered I can populate a new text box when a node is clicked on, but i'm not sure how to limit this so data is only displayed when lowest level node is clicked.

Also, I want to be able to edit the data shown and write the changes to the db.

Hmmm, any suggestions?

Donna.
 
I did something like this by putting a value ("Lowest") into the .tag property of the treeview if it was the lowest level. The database fields were in a single-record subform which was set to .visible = false on Form_Load then in the treeview click event I set the subform.visible = True if the treeview.tag was equal to "Lowest".

It worked Okay for me. PeteJ
(Contract Code-monkey)

It's amazing how many ways there are to skin a cat
(apologies to the veggies)
 
Thanks Pete. :-D

I now have a treeview that, when the lowest level child is clicked on, displays some editable fields. However, I have defined each of these fields as having a Control Source, which is a column from the database. For this reason, only the data from the first record is displayed, but it can be edited and automatically saved in the database.

What is the best way for me to make these fields show the data associated with the node clicked on, and allow changes made to be saved in the database?

Thanks again,
Donna
 
How about putting a selection statment into the .tag property like "[UniqueField] = " & ValueFromDatabase where UniqueField is the name of the column on the database table and ValueFromDatabase is (surprise, surprise) the value of that field for the record you have just read. Then you could do
Code:
if tvw.tag <> &quot;&quot; then
    if subForm.visible = true then
       docmd.close subform.name
    end if
    docmd.open subform.name, , , tvw.Tag
    subform.visible = true
end if
The parameter on the .open command is the filter criteria for opening the form. As long as you can specify it so that it is unique, when you open the subform it should only display the selected record. If the subform has been displayed before for a different record it must be closed and re-opened so that it displays the correct record. PeteJ
(Contract Code-monkey)

It's amazing how many ways there are to skin a cat
(apologies to the veggies)
 
Hi Pete,

Thanks for all your help, but I think we're working on different times (I'm in Australia)! The current status of my database is that I successfully test which node is clicked and the corresponding data fields appear on the form. :-D

If left(Node.Key, 3) = &quot;CH_&quot; Then
Me.RecordSource = &quot;SELECT * FROM Report &quot; _
& &quot;WHERE Name = '&quot; _
& Right(Node.Key, Len(Node.Key) - 3) & &quot;'&quot;
End If

My last final touch is to include code so a popup menu appears when a node is right-clicked on (which I have successfully tested for). I hope this to be similar to the popup menu in Explorer. I'm just not sure how to popup a menu that just reads &quot;New...&quot;, do I use MsgBox?

Thanks again, [2thumbsup]
Donna.
 
I was in Adelaide last Christmas & New Year but I'm back in the sunny (not) UK! [sad]

There is an InputBox function which lets the user key in some text and puts it into a field which you have defined:

strField = InputBox(&quot;Some text to describe the field&quot;, &quot;Box title&quot;, DefaultValue) PeteJ
(Contract Code-monkey)

It's amazing how many ways there are to skin a cat
(apologies to the veggies)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top