I am trying to build a treeview in my application based on a database.
The treeview I am looking to build is going out of bounds
The control is built from 4 tables
1: country (4 records)
2: county (106 records)
3: town (20018 records)
4: solicitors (54 records)
I have pasted the code below, I have gone wrong somewhere I am sure.
Private Sub treeview()
' Declare recordsets for each table
Dim rsCountry As Recordset
Dim rsCounty As Recordset
Dim rsTown As Recordset
Dim rsSolicitors As Recordset
' Set each recordset
Set rsCountry = mDBQuotes.OpenRecordset("tblCountry", dbOpenDynaset)
Set rsCounty = mDBQuotes.OpenRecordset("tblCounty", dbOpenDynaset)
Set rsTown = mDBQuotes.OpenRecordset("tblTowns", dbOpenDynaset)
Set rsSolicitors = mDBQuotes.OpenRecordset("tblSolicitors", dbOpenDynaset)
rsCountry.MoveFirst
Dim intIndex As Integer, intIndex2 As Integer, intIndex3 As Integer
Do Until rsCountry.EOF
Set mNode = TreeView1.Nodes.Add(1, tvwChild)
mNode.Text = rsCountry!Country
mNode.Tag = "Country"
mNode.key = rsCountry!countriesid & "country"
intIndex = mNode.Index
Do Until rsCounty.EOF
If rsCountry!countriesid = rsCounty!countriesid Then
Set mNode = TreeView1.Nodes.Add(intIndex, tvwChild)
mNode.Text = rsCounty!County
mNode.key = rsCounty!countiesid & "county"
mNode.Tag = "County"
mNode.Image = 2
intIndex2 = mNode.Index
End If
Do Until rsTown.EOF
If rsCounty!countiesid = rsTown!countiesid Then
Set mNode = TreeView1.Nodes.Add(intIndex2, tvwChild)
mNode.Text = rsTown!town
mNode.key = rsTown!townsid & "town"
mNode.Tag = "Town"
mNode.Image = 4
intIndex3 = mNode.Index
End If
Do Until rsSolicitors.EOF
If rsTown!townsid = rsSolicitors!townsid Then
Set mNode = TreeView1.Nodes.Add(intIndex3, tvwChild)
mNode.Text = rsSolicitors!CompanyName
mNode.key = rsSolicitors!solicitorsid & "solicitor"
mNode.Tag = "Solicitors"
mNode.Image = 6
End If
rsSolicitors.MoveNext
Loop
rsSolicitors.MoveFirst
rsTown.MoveNext
Loop
rsTown.MoveFirst
rsCounty.MoveNext
Loop
rsCounty.MoveFirst
rsCountry.MoveNext
Loop
End Sub
Can anybody give it a look as a fresh pair of eyes ??
Any help would be grateful
Regards
Matt
matt@begg-uk.co.uk
The treeview I am looking to build is going out of bounds
The control is built from 4 tables
1: country (4 records)
2: county (106 records)
3: town (20018 records)
4: solicitors (54 records)
I have pasted the code below, I have gone wrong somewhere I am sure.
Private Sub treeview()
' Declare recordsets for each table
Dim rsCountry As Recordset
Dim rsCounty As Recordset
Dim rsTown As Recordset
Dim rsSolicitors As Recordset
' Set each recordset
Set rsCountry = mDBQuotes.OpenRecordset("tblCountry", dbOpenDynaset)
Set rsCounty = mDBQuotes.OpenRecordset("tblCounty", dbOpenDynaset)
Set rsTown = mDBQuotes.OpenRecordset("tblTowns", dbOpenDynaset)
Set rsSolicitors = mDBQuotes.OpenRecordset("tblSolicitors", dbOpenDynaset)
rsCountry.MoveFirst
Dim intIndex As Integer, intIndex2 As Integer, intIndex3 As Integer
Do Until rsCountry.EOF
Set mNode = TreeView1.Nodes.Add(1, tvwChild)
mNode.Text = rsCountry!Country
mNode.Tag = "Country"
mNode.key = rsCountry!countriesid & "country"
intIndex = mNode.Index
Do Until rsCounty.EOF
If rsCountry!countriesid = rsCounty!countriesid Then
Set mNode = TreeView1.Nodes.Add(intIndex, tvwChild)
mNode.Text = rsCounty!County
mNode.key = rsCounty!countiesid & "county"
mNode.Tag = "County"
mNode.Image = 2
intIndex2 = mNode.Index
End If
Do Until rsTown.EOF
If rsCounty!countiesid = rsTown!countiesid Then
Set mNode = TreeView1.Nodes.Add(intIndex2, tvwChild)
mNode.Text = rsTown!town
mNode.key = rsTown!townsid & "town"
mNode.Tag = "Town"
mNode.Image = 4
intIndex3 = mNode.Index
End If
Do Until rsSolicitors.EOF
If rsTown!townsid = rsSolicitors!townsid Then
Set mNode = TreeView1.Nodes.Add(intIndex3, tvwChild)
mNode.Text = rsSolicitors!CompanyName
mNode.key = rsSolicitors!solicitorsid & "solicitor"
mNode.Tag = "Solicitors"
mNode.Image = 6
End If
rsSolicitors.MoveNext
Loop
rsSolicitors.MoveFirst
rsTown.MoveNext
Loop
rsTown.MoveFirst
rsCounty.MoveNext
Loop
rsCounty.MoveFirst
rsCountry.MoveNext
Loop
End Sub
Can anybody give it a look as a fresh pair of eyes ??
Any help would be grateful
Regards
Matt
matt@begg-uk.co.uk