palookavile
New member
- Local time
- Yesterday, 20:08
- Joined
- Nov 25, 2012
- Messages
- 3
This is a c/p of my problem from another forum, maybe some of you experts here can help me with this.
Somehow i managed to solve first problem as you will see, alltough i don't know if that's the correct way.
Anyway, here it goes:
FIRST problem:
So i am playing with this TreeViewSample database that i found on the web,
and basically i am trying to change the source that populates the tree, from table to a query.
I made a little combobox which is linked to a query, so when i change a value in combo box the records in query changes also,
and i wanted the treeview to display those records from the query.
So when i run the tree form i got that error message "No value given for one or more req..."
and after debug it highlights this row: varNodes.Open varSource, CurrentProject.Connection, adOpenStatic, adLockReadOnly, adCmdText
Prior to error, everywhere in the code i changed the source from "tblStaff" to "qryStaff", for example:
'Build the SQL that feeds the tree
strSQL = "SELECT BuildKey(StaffID) As NodeKey, FName & ' ' & LName As NodeText, BuildKey(Nz(ReportsTo,0)) As BelongTo" & _
" FROM qryStaff" & _
" UNION ALL SELECT TOP 1 BuildKey('<NULL>') As NodeKey, '<Un-Assigned>' As NodeText, BuildKey(0) As BelongsTo" & _
" FROM qryStaff" & _
" ORDER BY NodeText"
Am i doing this in a right way at all?
If not could you please tell me what to do, or what am i doing wrong.
Note that i have very small code-ing experience, obviously.
CURRENT problem:
So i managed to bypass this problem by leaving the "tblStaff" and just added this highlighted text in the strSQL:
strSQL = "SELECT BuildKey(StaffID) As NodeKey, FName & ' ' & LName As NodeText, BuildKey(Nz(ReportsTo,0)) As BelongTo" & _
" FROM tblStaff WHERE bossID=" & Forms.frmCombo.Combo7 & _
" UNION ALL SELECT TOP 1 BuildKey('<NULL>') As NodeKey, '<Un-Assigned>' As NodeText, BuildKey(0) As BelongsTo" & _
" FROM tblStaff" & _
" ORDER BY NodeText"
I will upload a cleaner version of this db i'm working on so if you want to see it and help me, i would be very thankfull.
So basically, i can have many bosses, and every boss can have many staff under him that are in a hierarchical order (there is a procedure that sorts them).
I want to choose bossID in combo form, so that when i press the treeview button, it opens the treview form with staff under him in a tree hierarchy. (this works now)
I would like to know if there is a way to now flatten this treeview, and write it in a new table in that exact order like it is in the tree.
I need this so i can make a report with this flat hierarchy.
The other thing that's bothering me is that when i put a new boss in the table, and start filling the staff under him (self join table), when i come to the reportsTo field,
it lists ALL of the staff that has been entered allready. So if i "accidentaly" chose a staff record that is related to some prior bossID, it gives me error.
And that is ofcourse because of this line: WHERE bossID=" & Forms.frmCombo.Combo7.
Is there any way that i could restrict this reportsTo field so that it offers me just these "new" records that i'm filling for this new bossID?
Please help.
Somehow i managed to solve first problem as you will see, alltough i don't know if that's the correct way.
Anyway, here it goes:
FIRST problem:
So i am playing with this TreeViewSample database that i found on the web,
and basically i am trying to change the source that populates the tree, from table to a query.
I made a little combobox which is linked to a query, so when i change a value in combo box the records in query changes also,
and i wanted the treeview to display those records from the query.
So when i run the tree form i got that error message "No value given for one or more req..."
and after debug it highlights this row: varNodes.Open varSource, CurrentProject.Connection, adOpenStatic, adLockReadOnly, adCmdText
Prior to error, everywhere in the code i changed the source from "tblStaff" to "qryStaff", for example:
'Build the SQL that feeds the tree
strSQL = "SELECT BuildKey(StaffID) As NodeKey, FName & ' ' & LName As NodeText, BuildKey(Nz(ReportsTo,0)) As BelongTo" & _
" FROM qryStaff" & _
" UNION ALL SELECT TOP 1 BuildKey('<NULL>') As NodeKey, '<Un-Assigned>' As NodeText, BuildKey(0) As BelongsTo" & _
" FROM qryStaff" & _
" ORDER BY NodeText"
Am i doing this in a right way at all?
If not could you please tell me what to do, or what am i doing wrong.
Note that i have very small code-ing experience, obviously.
CURRENT problem:
So i managed to bypass this problem by leaving the "tblStaff" and just added this highlighted text in the strSQL:
strSQL = "SELECT BuildKey(StaffID) As NodeKey, FName & ' ' & LName As NodeText, BuildKey(Nz(ReportsTo,0)) As BelongTo" & _
" FROM tblStaff WHERE bossID=" & Forms.frmCombo.Combo7 & _
" UNION ALL SELECT TOP 1 BuildKey('<NULL>') As NodeKey, '<Un-Assigned>' As NodeText, BuildKey(0) As BelongsTo" & _
" FROM tblStaff" & _
" ORDER BY NodeText"
I will upload a cleaner version of this db i'm working on so if you want to see it and help me, i would be very thankfull.
So basically, i can have many bosses, and every boss can have many staff under him that are in a hierarchical order (there is a procedure that sorts them).
I want to choose bossID in combo form, so that when i press the treeview button, it opens the treview form with staff under him in a tree hierarchy. (this works now)
I would like to know if there is a way to now flatten this treeview, and write it in a new table in that exact order like it is in the tree.
I need this so i can make a report with this flat hierarchy.
The other thing that's bothering me is that when i put a new boss in the table, and start filling the staff under him (self join table), when i come to the reportsTo field,
it lists ALL of the staff that has been entered allready. So if i "accidentaly" chose a staff record that is related to some prior bossID, it gives me error.
And that is ofcourse because of this line: WHERE bossID=" & Forms.frmCombo.Combo7.
Is there any way that i could restrict this reportsTo field so that it offers me just these "new" records that i'm filling for this new bossID?
Please help.