Displaying Two Different Tables Data In One Treeview

N

nltait

Hi,
Is there anyway to fill a Treeview with information from one access column in
a table and then have a branch off that which displays data from another
column in a separate table? I can display data in my treeview but only if the
data is from two columns in the same table. Please Help!!

This is my current code (see Bellow). The line of code ( Set rs = db.
OpenRecordset("SELECT DISTINCT [user name] FROM custodian WHERE Name='" & rs2
("Name") & "'")) which is highlighted by this *** is where it accesses the
information from the 'Custodian' table. Its is currently getting the 'user
name' and 'name' columns. i would like it to get the User Name from that
table but branching off from that i would like the 'Asset Name' column from
the 'asset master' table. I no its very complicated, any help would be very
much appreciated. ive attached a picture of what the treeview table looks
like at the moment. hopefully i have explained everything in great enough
detail. Thank you in advance.

Option Compare Database
Option Explicit

Private Sub Custodian_history_form_Load()

With Me.[Custodian History Form]
Style = 6
LineStyle = tvwRootLines
Indentation = 240
Appearance = ccFlat
HideSelection = False
BorderStyle = ccFixedSingle
HotTracking = True
FullRowSelect = True
Checkboxes = False
SingleSel = False
Sorted = False
Scroll = True
LabelEdit = tvwManual
Font.Name = "Verdana"
Font.Size = 9
End With

Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strQuery1 As String
Dim nod As Object
Dim nodChild As Object
Dim strNode1Text As String
Dim strVisibleText As String
Dim strMessage As String
Dim intVBMsg As Integer
Dim intCounter As Integer
Dim stringcount As String
Dim strQuery2 As String
Dim rs2 As DAO.Recordset
Dim strNode2Text As String
Dim db2 As DAO.Database
Dim rs3 As DAO.Recordset

Me.[Custodian History Form].Nodes.Add Text:="Custodian History", Key:
="Custodianhistory987"
strQuery2 = "select DISTINCT Name from [Custodian]"
Set db = CurrentDb
Set rs2 = db.OpenRecordset(strQuery2)
With Me.[Custodian History Form]
Do Until rs2.EOF
strNode2Text = StrConv("Level1" & rs2!Name, vbLowerCase)
strVisibleText = rs2!Name


'if model name is null, will have problem
If IsNull(rs2!Name) Then
MsgBox "number is null"
strVisibleText = "no name"
End If
stringcount = CStr(intCounter)
strNode2Text = strNode2Text + stringcount
Set nod = Me.[Custodian History Form].Nodes.Add(Relative:
="Custodianhistory987", relationship:=tvwChild, Key:=strNode2Text, Text:
=strVisibleText)


'Now add the child root for this Asset Name
***Set rs = db.OpenRecordset("SELECT DISTINCT [user name] FROM custodian
WHERE Name='" & rs2("Name") & "'")
Do Until rs.EOF
Set nodChild = .Nodes.Add(Relative:=strNode2Text, relationship:=tvwChild,
Text:=rs("user name"))
nodChild.Expanded = False
rs.MoveNext
Loop
rs2.MoveNext

Loop

End With
Set rs2 = Nothing
Set db = Nothing
End Sub
 
T

Tom van Stiphout

So you already know how to handle columns from a single table. How
about columns from a single query? I'm sure you could handle that. So
create a query with both tables, and a join line between them, that
outputs the columns you are interested in, and base your treeview on
it.

-Tom.
Microsoft Access MVP

Hi,
Is there anyway to fill a Treeview with information from one access column in
a table and then have a branch off that which displays data from another
column in a separate table? I can display data in my treeview but only if the
data is from two columns in the same table. Please Help!!

This is my current code (see Bellow). The line of code ( Set rs = db.
OpenRecordset("SELECT DISTINCT [user name] FROM custodian WHERE Name='" & rs2
("Name") & "'")) which is highlighted by this *** is where it accesses the
information from the 'Custodian' table. Its is currently getting the 'user
name' and 'name' columns. i would like it to get the User Name from that
table but branching off from that i would like the 'Asset Name' column from
the 'asset master' table. I no its very complicated, any help would be very
much appreciated. ive attached a picture of what the treeview table looks
like at the moment. hopefully i have explained everything in great enough
detail. Thank you in advance.

Option Compare Database
Option Explicit

Private Sub Custodian_history_form_Load()

With Me.[Custodian History Form]
Style = 6
LineStyle = tvwRootLines
Indentation = 240
Appearance = ccFlat
HideSelection = False
BorderStyle = ccFixedSingle
HotTracking = True
FullRowSelect = True
Checkboxes = False
SingleSel = False
Sorted = False
Scroll = True
LabelEdit = tvwManual
Font.Name = "Verdana"
Font.Size = 9
End With

Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strQuery1 As String
Dim nod As Object
Dim nodChild As Object
Dim strNode1Text As String
Dim strVisibleText As String
Dim strMessage As String
Dim intVBMsg As Integer
Dim intCounter As Integer
Dim stringcount As String
Dim strQuery2 As String
Dim rs2 As DAO.Recordset
Dim strNode2Text As String
Dim db2 As DAO.Database
Dim rs3 As DAO.Recordset

Me.[Custodian History Form].Nodes.Add Text:="Custodian History", Key:
="Custodianhistory987"
strQuery2 = "select DISTINCT Name from [Custodian]"
Set db = CurrentDb
Set rs2 = db.OpenRecordset(strQuery2)
With Me.[Custodian History Form]
Do Until rs2.EOF
strNode2Text = StrConv("Level1" & rs2!Name, vbLowerCase)
strVisibleText = rs2!Name


'if model name is null, will have problem
If IsNull(rs2!Name) Then
MsgBox "number is null"
strVisibleText = "no name"
End If
stringcount = CStr(intCounter)
strNode2Text = strNode2Text + stringcount
Set nod = Me.[Custodian History Form].Nodes.Add(Relative:
="Custodianhistory987", relationship:=tvwChild, Key:=strNode2Text, Text:
=strVisibleText)


'Now add the child root for this Asset Name
***Set rs = db.OpenRecordset("SELECT DISTINCT [user name] FROM custodian
WHERE Name='" & rs2("Name") & "'")
Do Until rs.EOF
Set nodChild = .Nodes.Add(Relative:=strNode2Text, relationship:=tvwChild,
Text:=rs("user name"))
nodChild.Expanded = False
rs.MoveNext
Loop
rs2.MoveNext

Loop

End With
Set rs2 = Nothing
Set db = Nothing
End Sub
 
N

nltait

thats the problem, im very new to all this stuff. i dont really understand
much. it took me a long time to write the previous code which i sent. is
there anyway you could give me some examples or something a bit more detailed?
thank you tom
So you already know how to handle columns from a single table. How
about columns from a single query? I'm sure you could handle that. So
create a query with both tables, and a join line between them, that
outputs the columns you are interested in, and base your treeview on
it.

-Tom.
Microsoft Access MVP
Hi,
Is there anyway to fill a Treeview with information from one access column in
[quoted text clipped - 91 lines]
Set db = Nothing
End Sub
 
C

Chegu Tom

Go to the new query wizard

Select your two tables. use your mouse to draw a line between the linked
fields
drag the fields you want a columns from each table to the grid below

Your query will work just like a table that had all those fields




nltait said:
thats the problem, im very new to all this stuff. i dont really understand
much. it took me a long time to write the previous code which i sent. is
there anyway you could give me some examples or something a bit more
detailed?
thank you tom
So you already know how to handle columns from a single table. How
about columns from a single query? I'm sure you could handle that. So
create a query with both tables, and a join line between them, that
outputs the columns you are interested in, and base your treeview on
it.

-Tom.
Microsoft Access MVP
Hi,
Is there anyway to fill a Treeview with information from one access
column in
[quoted text clipped - 91 lines]
Set db = Nothing
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top