I have the following code which is used quite a bit on a form to update some summary values and was wondering if anyone can help me speed this up as there are about 200 people records it goes through... Its isin't particurarly slow. prob about 2 seconds but was wondering how I can speed that up the recordset in any way.
regards,
Neemi
Code:
'// calculate available resource
Dim rsP As Recordset
Dim rsT As Recordset
Dim vSDate As Date
Dim vEDate As Date
Dim vCDate As Date
Set rsP = CurrentDb.OpenRecordset("SELECT * FROM tblPerson")
Set rsT = CurrentDb.OpenRecordset("SELECT * FROM tblSummaryDetails_Temp WHERE 1 = 0")
rsP.MoveFirst
Do Until rsP.EOF
vSDate = DateAdd("W", -4, vCurrDate) '// First date of 1st weekending
vEDate = DateAdd("W", 84, vCurrDate) '// Last date of 12th weekending
vCDate = vSDate
Do While Format(vCDate, "YYYYMMDD") <= Format(vEDate, "YYYYMMDD")
rsT.AddNew
rsT![Type] = "R"
rsT![DT_W] = "Dt_W" & fWeekNum(vCurrDate, fWeekending(vCDate)) & "_D" & Weekday(vCDate, 2)
rsT![PersID] = rsP![PersID]
If IsNull(rsP![sdate]) Or Format(rsP![sdate], "YYYYMMDD") <= Format(vCDate, "YYYYMMDD") Then
If IsNull(rsP![Edate]) Or Format(rsP![Edate], "YYYYMMDD") >= Format(vCDate, "YYYYMMDD") Then
rsT![Available] = 8
Else
rsT![Available] = 0
End If
Else
rsT![Available] = 0
End If
rsT.Update
Do
vCDate = DateAdd("D", 1, vCDate)
Loop While Weekday(vCDate, 2) = 6 Or Weekday(vCDate, 2) = 7
Loop
rsP.MoveNext
Loop
rsP.Close: Set rsP = Nothing
rsT.Close: Set rsT = Nothing
regards,
Neemi