Hi David,
It looks as if you're doing an awful lot of appending and deleting
records in table that hold values for intermediate steps in your
calculation. It's certain that all the appending and deleting is what is
bloating your database: Jet does not recover space used by deleted
records until you explicitly compact the database.
So a sensible step would be to put these - effectively temporary -
tables into a separate mdb file. This is a common and strongly
recommended technique to overcome the bloating problem when database
operations require creation and deletion of temporary records.
You can either use a "standing" mdb file for these intermediate tables,
and run code to compact it after each round of deletions - or have your
code create a "throwaway" mdb as often as needed, deleting it after use.
This should overcome your current bloating problem. Later, there may
still be benefits in re-examining your algorithm along the lines Dale
suggested.
Below is the code, but an explaination first what it does.
The basic goal is to rank teams based on 1) avg margin of victory + the avg
margin of victory of their opponets + their opp + their opp, take that
weighted value (Power Ranking) and 2) Compare the Power ranking verse actual
score (adjusted for home field advantage) so that if a team with a power
ranking of 20 plays one with a power ranking of 10 and wins by 8 the higher
rank team would have a game performance of 19 (((20 +30)/2) +8/2)) and the
lower ranked team performance would be 11. Performance of each team is
averaged together for each game to come up with a "quality ranking" this
ranking is used for a second comparision and then that to a third and so on
.....
Because of the complexity I have found that if I break down the task into
several series of queries and dump these query results into a table my system
can handle for the most part...accept I need to take the number of loops
maybe one or two thousand iterations before it stablizes and that is when I
have problems.
The way I have queries named gives hints of the function and I have not
included those queries here - I will if you still think it will help. Queries
that begin with numbers 111, 116, 121 & 121e find #1 process described above,
143 and 153 queries and tables are to handle the looping process.
Private Sub cmdDiv1ARanking_Click()
txtTimeStart.Value = Now
counter = 0
If (IsNull(Me.txtSeason) Or IsNull(Me.txtEndSeason)) Then
MsgBox "Both years required."
Else
EndSeason = txtEndSeason.Value
Season = txtSeason.Value - 1
Do
Season = Season + 1
txtSeason.Value = Season
Refresh
DoCmd.OpenQuery "Season Division Conference School - Duplicates",
acViewNormal, acReadOnly
DoCmd.Close
DoCmd.OpenTable "Filter Parameters", acNormal, acEdit
DoCmd.Close
strSql = "DELETE * FROM [111 Avg Adjusted Margin DB]"
CurrentDb.Execute strSql, dbFailOnError
strSql = "INSERT INTO [111 Avg Adjusted Margin DB] SELECT [111 Avg
Adjusted Margin].* FROM [111 Avg Adjusted Margin]"
CurrentDb.Execute strSql, dbFailOnError
txt111.Value = "Completed"
strSql = "DELETE * FROM [116 Opp Avg Margin DB]"
CurrentDb.Execute strSql, dbFailOnError
strSql = "INSERT INTO [116 Opp Avg Margin DB] SELECT [116 Opp Avg
Margin].* FROM [116 Opp Avg Margin]"
CurrentDb.Execute strSql, dbFailOnError
txt116.Value = "Completed"
strSql = "DELETE * FROM [121 Opp Opp Avg Margin DB]"
CurrentDb.Execute strSql, dbFailOnError
strSql = "INSERT INTO [121 Opp Opp Avg Margin DB] SELECT [121 Opp Opp
Avg Margin].* FROM [121 Opp Opp Avg Margin]"
CurrentDb.Execute strSql, dbFailOnError
txt121.Value = "Completed"
strSql = "DELETE * FROM [121e Opp Opp Opp Avg Margin DB]"
CurrentDb.Execute strSql, dbFailOnError
strSql = "INSERT INTO [121e Opp Opp Opp Avg Margin DB] SELECT [121e Opp
Opp Opp Avg Margin].* FROM [121e Opp Opp Opp Avg Margin]"
CurrentDb.Execute strSql, dbFailOnError
strSql = "DELETE * FROM [122 Power Rankings DB]"
CurrentDb.Execute strSql, dbFailOnError
strSql = "INSERT INTO [122 Power Rankings DB] SELECT [122 Power
Rankings].* FROM [122 Power Rankings]"
CurrentDb.Execute strSql, dbFailOnError
strSql = "DELETE * FROM [143 Quality Scores Union Query DB]"
CurrentDb.Execute strSql, dbFailOnError
strSql = "INSERT INTO [143 Quality Scores Union Query DB] SELECT [143c
Quality Scores].* FROM [143c Quality Scores]"
CurrentDb.Execute strSql, dbFailOnError
counter = 0
myNum = 1
Do
myNum = myNum + 1
Text_LoopNo.Value = myNum
strSql = "DELETE * FROM [153 Quality Scores Union Query DB]"
CurrentDb.Execute strSql, dbFailOnError
strSql = "INSERT INTO [153 Quality Scores Union Query DB] SELECT [153c
Quality Scores].* FROM [153c Quality Scores]"
CurrentDb.Execute strSql, dbFailOnError
strSql = "DELETE * FROM [143 Quality Scores Union Query DB]"
CurrentDb.Execute strSql, dbFailOnError
strSql = "INSERT INTO [143 Quality Scores Union Query DB] SELECT [153
Quality Scores Union Query DB].* FROM [153 Quality Scores Union Query DB]"
CurrentDb.Execute strSql, dbFailOnError
counter = counter + 1
Loop Until myNum = 1024
txtTimeFinished.Value = Now
strSql = "DELETE * FROM [802 Div 1A Rankings]"
CurrentDb.Execute strSql, dbFailOnError
strSql = "INSERT INTO [802 Div 1A Rankings] SELECT [153 Quality Scores
Union Query DB].* FROM [153 Quality Scores Union Query DB]"
CurrentDb.Execute strSql, dbFailOnError
counter = counter + 1
Loop Until Season = EndSeason
End If
txtTimeFinished.Value = Now
End Sub