K
Ken Warthen
I have an ActiveX treeview control on a form in an Access 2007 database. The
treeview loads data from a table of roughly 4,000 records. There are six
levels in the treeview. It takes an incredible amount of time to load the
data; about a half hour. If anyone out there is well versed in this control,
I'd be very appreciative for any advise on how to improve the load time with
this control. My code follows.
TIA,
Ken
Private Sub Form_Load()
On Error GoTo PROC_ERROR
Dim rsFSMG As DAO.Recordset
Dim rsRegion As DAO.Recordset
Dim rsOwner As DAO.Recordset
Dim rsSalesCenter As DAO.Recordset
Dim rsCustomer As DAO.Recordset
Dim strSQL1 As String
Dim strSQL2 As String
Dim strSQL3 As String
Dim strSQL4 As String
Dim strSQL5 As String
Dim tvw As TreeView
Dim strNodeName As String
Dim strRegion As String
Dim strOwner As String
Dim strSalesCenter As String
Dim strCustomer As String
Dim theNode As Node
Dim theRegion As Node
Dim theOwner As Node
Dim theSalesCenter As Node
Dim theCustomer As Node
DoCmd.OpenForm "frmLoadingFormMessage"
DoEvents
Me.visible = False
'load the treeview control
Set tvw = Me.tvwNodes.Object
tvw.Nodes.Clear
'Level 1 — FSMG Regions
strSQL1 = "SELECT DISTINCT [FSMGRegionID],[FSMGRegion] FROM tblMain"
Set rsFSMG = CurrentDb.OpenRecordset(strSQL1)
With rsFSMG
.MoveFirst
Do Until rsFSMG.EOF
strNodeName = rsFSMG.Fields("FSMGRegion")
Set theNode = Me.tvwNodes.Nodes.Add(, , , strNodeName)
'Level 2 — Regions
strSQL2 = "SELECT DISTINCT [Region] FROM tblMain WHERE
[FSMGRegion] ='" & strNodeName & "'"
Set rsRegion = CurrentDb.OpenRecordset(strSQL2)
With rsRegion
.MoveFirst
Do Until rsRegion.EOF
strRegion = .Fields("Region")
Set theRegion = Me.tvwNodes.Nodes.Add(theNode,
tvwChild, , strRegion)
'Level 3 — Owner
strSQL3 = "SELECT DISTINCT [Owner] FROM tblMain
WHERE [Region]='" & strRegion & "'"
Set rsOwner = CurrentDb.OpenRecordset(strSQL3)
With rsOwner
.MoveFirst
Do Until .EOF
strOwner = .Fields("Owner")
Set theOwner =
Me.tvwNodes.Nodes.Add(theRegion, tvwChild, , strOwner)
'Level 4 — Sales Centers/Branch
strSQL4 = "SELECT DISTINCT [SalesCenter]
FROM tblMain WHERE [Owner]='" & strOwner & "'"
Set rsSalesCenter =
CurrentDb.OpenRecordset(strSQL4)
With rsSalesCenter
.MoveFirst
Do Until .EOF
strSalesCenter =
..Fields("SalesCenter")
Set theCustomer =
Me.tvwNodes.Nodes.Add(theOwner, tvwChild, , strCustomer)
'Level 5 — Customer/Account
strSQL5 = "SELECT DISTINCT
[Customer] FROM tblMain WHERE [SalesCenter]='" & strCustomer & "'"
Set rsCustomer =
CurrentDb.OpenRecordset(strSQL5)
With rsCustomer
.MoveFirst
Do Until .EOF
strCustomer =
..Fields("Customer")
Set theCustomer =
Me.tvwNodes.Nodes.Add(theCustomer, tvwChild, , strCustomer)
.MoveNext
Loop
End With
.MoveNext
Loop
End With
.MoveNext
Loop
End With
.MoveNext
Loop
End With
.MoveNext
Loop
End With
rsFSMG.Close
rsRegion.Close
rsOwner.Close
rsCustomer.Close
rsCustomer.Close
Set rsFSMG = Nothing
Set rsRegion = Nothing
Set rsOwner = Nothing
Set rsCustomer = Nothing
Set rsCustomer = Nothing
Me.visible = True
DoCmd.Close acForm, "frmLoadingFormMessage"
PROC_EXIT:
Exit Sub
PROC_ERROR:
Call ShowError("frmViewPromotions", "Form_Load", Err.Number,
Err.Description, Err.Source)
Resume PROC_EXIT
Resume
End Sub
treeview loads data from a table of roughly 4,000 records. There are six
levels in the treeview. It takes an incredible amount of time to load the
data; about a half hour. If anyone out there is well versed in this control,
I'd be very appreciative for any advise on how to improve the load time with
this control. My code follows.
TIA,
Ken
Private Sub Form_Load()
On Error GoTo PROC_ERROR
Dim rsFSMG As DAO.Recordset
Dim rsRegion As DAO.Recordset
Dim rsOwner As DAO.Recordset
Dim rsSalesCenter As DAO.Recordset
Dim rsCustomer As DAO.Recordset
Dim strSQL1 As String
Dim strSQL2 As String
Dim strSQL3 As String
Dim strSQL4 As String
Dim strSQL5 As String
Dim tvw As TreeView
Dim strNodeName As String
Dim strRegion As String
Dim strOwner As String
Dim strSalesCenter As String
Dim strCustomer As String
Dim theNode As Node
Dim theRegion As Node
Dim theOwner As Node
Dim theSalesCenter As Node
Dim theCustomer As Node
DoCmd.OpenForm "frmLoadingFormMessage"
DoEvents
Me.visible = False
'load the treeview control
Set tvw = Me.tvwNodes.Object
tvw.Nodes.Clear
'Level 1 — FSMG Regions
strSQL1 = "SELECT DISTINCT [FSMGRegionID],[FSMGRegion] FROM tblMain"
Set rsFSMG = CurrentDb.OpenRecordset(strSQL1)
With rsFSMG
.MoveFirst
Do Until rsFSMG.EOF
strNodeName = rsFSMG.Fields("FSMGRegion")
Set theNode = Me.tvwNodes.Nodes.Add(, , , strNodeName)
'Level 2 — Regions
strSQL2 = "SELECT DISTINCT [Region] FROM tblMain WHERE
[FSMGRegion] ='" & strNodeName & "'"
Set rsRegion = CurrentDb.OpenRecordset(strSQL2)
With rsRegion
.MoveFirst
Do Until rsRegion.EOF
strRegion = .Fields("Region")
Set theRegion = Me.tvwNodes.Nodes.Add(theNode,
tvwChild, , strRegion)
'Level 3 — Owner
strSQL3 = "SELECT DISTINCT [Owner] FROM tblMain
WHERE [Region]='" & strRegion & "'"
Set rsOwner = CurrentDb.OpenRecordset(strSQL3)
With rsOwner
.MoveFirst
Do Until .EOF
strOwner = .Fields("Owner")
Set theOwner =
Me.tvwNodes.Nodes.Add(theRegion, tvwChild, , strOwner)
'Level 4 — Sales Centers/Branch
strSQL4 = "SELECT DISTINCT [SalesCenter]
FROM tblMain WHERE [Owner]='" & strOwner & "'"
Set rsSalesCenter =
CurrentDb.OpenRecordset(strSQL4)
With rsSalesCenter
.MoveFirst
Do Until .EOF
strSalesCenter =
..Fields("SalesCenter")
Set theCustomer =
Me.tvwNodes.Nodes.Add(theOwner, tvwChild, , strCustomer)
'Level 5 — Customer/Account
strSQL5 = "SELECT DISTINCT
[Customer] FROM tblMain WHERE [SalesCenter]='" & strCustomer & "'"
Set rsCustomer =
CurrentDb.OpenRecordset(strSQL5)
With rsCustomer
.MoveFirst
Do Until .EOF
strCustomer =
..Fields("Customer")
Set theCustomer =
Me.tvwNodes.Nodes.Add(theCustomer, tvwChild, , strCustomer)
.MoveNext
Loop
End With
.MoveNext
Loop
End With
.MoveNext
Loop
End With
.MoveNext
Loop
End With
.MoveNext
Loop
End With
rsFSMG.Close
rsRegion.Close
rsOwner.Close
rsCustomer.Close
rsCustomer.Close
Set rsFSMG = Nothing
Set rsRegion = Nothing
Set rsOwner = Nothing
Set rsCustomer = Nothing
Set rsCustomer = Nothing
Me.visible = True
DoCmd.Close acForm, "frmLoadingFormMessage"
PROC_EXIT:
Exit Sub
PROC_ERROR:
Call ShowError("frmViewPromotions", "Form_Load", Err.Number,
Err.Description, Err.Source)
Resume PROC_EXIT
Resume
End Sub