D
Danny J. Lesandrini
I'm working on a database application created by a different developer
and he does something I never have. Wondering if his approach is better
than what I'm accustomed to doing.
Open first recordset of "Types", which will have 2 to 4 records:
Type
--------
Red
Yellow
Blue
Next, he opens another recordset to find the "SubTypes"
Type SubType
---------- ---------------------
Red Apple
Blue Sno Cone
Red Strawberry
Yellow Bannana
The second recordset is opened without sorting or filtering and he uses
the FindFirst and FindNext methods to locate associated records while
looping through the first recordset. (caution, air code follows)
Do Until rstType.EOF
sType = rstType!Type
sCriteria = "[Type]='" & sType & "'"
rstSubType.FindFirst sCriteria
Do While Not rsProgs.NoMatch
' do stuff here
rstSubType.FindNext sCriteria
Loop
rstType.MoveNext
Loop
I changed the code so that it creates a new, filtered, ordered recordset
of subtypes and processes them all, since they all are associated with Type.
Do Until rstType.EOF
sType = rstType!Type
sSQL = "Select * From SubTypes WhereType='" & sType & "' Order By SubType"
Set rstSubType = dbs.OpenRecordset(sSQL, dbOpenSnapshot)
Do Until rstSubType.EOF
' do stuff here
rstSubType.MoveNext
Loop
Set rstSubType = Nothing
rstType.MoveNext
Loop
I like the cleanness of my method better, but what are your expectations on
performance? These are used to load a TreeView control and will never
contain more than a handfull of values for either Type or SubType.
and he does something I never have. Wondering if his approach is better
than what I'm accustomed to doing.
Open first recordset of "Types", which will have 2 to 4 records:
Type
--------
Red
Yellow
Blue
Next, he opens another recordset to find the "SubTypes"
Type SubType
---------- ---------------------
Red Apple
Blue Sno Cone
Red Strawberry
Yellow Bannana
The second recordset is opened without sorting or filtering and he uses
the FindFirst and FindNext methods to locate associated records while
looping through the first recordset. (caution, air code follows)
Do Until rstType.EOF
sType = rstType!Type
sCriteria = "[Type]='" & sType & "'"
rstSubType.FindFirst sCriteria
Do While Not rsProgs.NoMatch
' do stuff here
rstSubType.FindNext sCriteria
Loop
rstType.MoveNext
Loop
I changed the code so that it creates a new, filtered, ordered recordset
of subtypes and processes them all, since they all are associated with Type.
Do Until rstType.EOF
sType = rstType!Type
sSQL = "Select * From SubTypes WhereType='" & sType & "' Order By SubType"
Set rstSubType = dbs.OpenRecordset(sSQL, dbOpenSnapshot)
Do Until rstSubType.EOF
' do stuff here
rstSubType.MoveNext
Loop
Set rstSubType = Nothing
rstType.MoveNext
Loop
I like the cleanness of my method better, but what are your expectations on
performance? These are used to load a TreeView control and will never
contain more than a handfull of values for either Type or SubType.