Help with Treeview (1 Viewer)

Prysson

Registered User.
Local time
Today, 16:02
Joined
Sep 23, 2002
Messages
45
I fill out a treeview based on a series of tables that represents locations.

For example

tblLocation
LocationID
Location

tblArea
LocationID
AreaID
Area

tblRow
AreaID
RowID
Row

tblPlot
RowID
PlotID
Plot

The Treeview uses the following code to populate itself in the form.

Dim NodX As Node


With rs
.ActiveConnection = CurrentProject.Connection
.CursorLocation = adUseServer
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open "SELECT * FROM tblArea WHERE tblArea.AreaName <> 'na' And tblArea.AreaActive = True And tblArea.LocationID = " & Me!cmbLocation & " ORDER BY tblArea.AreaName;"

End With

If rs.EOF Then
MsgBox "There are no Active Area's in the Location.", vbOKOnly + vbCritical, "Error"
Me!cmbLocation.SetFocus
Else
Do While Not rs.EOF
With Me!TreeViewLocation
.Nodes.Add , , "Area " & CStr(rs!AreaID), rs!AreaName, 1
End With
rs.MoveNext
Loop

rs.Close
Set rs = Nothing

Set rs = New ADODB.Recordset
With rs
.ActiveConnection = CurrentProject.Connection
.CursorLocation = adUseServer
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open "SELECT tblLocation.LocationID, tblLocation.LocationName, tblArea.LocationID, tblArea.AreaName, tblRow.RowID, tblRow.AreaID, tblRow.RowNumber, tblRow.RowActive From tblLocation, tblArea, tblRow Where tblLocation.LocationID = " & Me!cmbLocation & " And tblArea.LocationID = tblLocation.LocationID And tblRow.AreaID = tblArea.AreaID And tblRow.RowActive = True;"
End With

Do While Not rs.EOF
With Me!TreeViewLocation
.Nodes.Add "Area " & CStr(rs!AreaID), tvwChild, "Row " & CStr(rs!RowID), rs!RowNumber, 2
End With
rs.MoveNext
Loop

rs.Close
Set rs = Nothing

Set rs = New ADODB.Recordset
With rs
.ActiveConnection = CurrentProject.Connection
.CursorLocation = adUseServer
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open "SELECT tblLocation.LocationID, tblLocation.LocationName, tblArea.AreaID, tblArea.AreaName, tblRow.RowID, tblRow.RowNumber, tblPlot.PlotID, tblPlot.Plot, tblPlot.PlotActive FROM tblLocation, tblArea, tblRow, tblPlot WHERE tblLocation.LocationID = " & Me!cmbLocation & " And tblArea.LocationID = tblLocation.LocationID And tblRow.AreaID = tblArea.AreaID And tblPlot.RowID = tblRow.RowID And tblPlot.PlotActive = True;"
End With

Do While Not rs.EOF
With Me!TreeViewLocation
.Nodes.Add "Row " & CStr(rs!RowID), tvwChild, "Plot " & CStr(rs!PlotID), rs!Plot, 3
End With
rs.MoveNext
Loop

rs.Close
Set rs = Nothing



There is another table...

Call it tblJoinEventLocation

This table links events to locations.

Normally the above treeview would be used to select a location where the event occurs.

It would be recorded by joining the location to the event...

thus there would be an entry

tblJoinEventLocation
EventID
LocationID
AreaID
RowID
PlotID


If we assume that the treeview is already build based on the code I displayed initially.

Then by building a second recordset as shown

Select * tblJoinEventLocation Where tblJoinEventLocation.EventID = " & lng & " AND tblJoinEventLocation.LocationID = " & Me!cmbLocation & "


How can I get the treeview nodes to be checked that correspond to the values in the second recordset.
 

Users who are viewing this thread

Top Bottom