hi the problem i have is that i cant get the value out of a query without setting/restting the recordset every time. and this takes ages ( about 1 sec but * 10,000 times)
i was originally using Dlookup to get the value out of the query but this is even worse!
my code is as follows as you can see each time i go aroud the loop i have to set the recordset to refresh it and get the new value strored in the query
hope someone can help becaue i'm all out of ideas.
i've cut this bit out to show how i'm trying to get the result of a query out into a variable and look
if anyone can help speed this up i'd be sooooo greatful
thanks
Matt
i was originally using Dlookup to get the value out of the query but this is even worse!
my code is as follows as you can see each time i go aroud the loop i have to set the recordset to refresh it and get the new value strored in the query
hope someone can help becaue i'm all out of ideas.
Code:
Set rstd2 = currentdb.OpenRecordset("SC_Volume_BU_Calculated")
Set rstd1 = currentdb.OpenRecordset("TempProjectList")
For i = 0 To rstd1.RecordCount - 1
For j = 1 To 13
' =========================== put a list of projects into the answers table= ===========================
sqlstring = "Select sum ([SC_Volume_BU_Calculated].[Budgeted_Units]) as SUMBU FROM [SC_Volume_BU_Calculated] " & _
"Where [SC_Volume_BU_Calculated].[Project_ID] = " & Chr(34) & projID & Chr(34) & " " & _
"and [SC_Volume_BU_Calculated].[Period_Number] = " & Chr(34) & j & Chr(34) & " " & _
"AND [SC_Volume_BU_Calculated].[cat] > '73' "
Set myqdf = currentdb.CreateQueryDef("append1", sqlstring)
Set rstdappend1 = currentdb.OpenRecordset("append1")
rstdappend1.MoveFirst
BUVariable3 = 0.33 * (rstdappend1.Fields("SUMBU").Value)
myqdf.Close
Set myqdf = Nothing
currentdb.QueryDefs.Delete "append1"
If IsNull(BUVariable3) Then
BUVariable3 = 0
End If
BUVariable3 = BUVariable2 + BUVariable3
sqlstring = "UPDATE [Volume Answers SC] SET [Volume Answers SC].[Budgeted Units] = " & Chr(34) & _
BUVariable3 & Chr(34) & " WHERE [Volume Answers SC].Project_ID = " & Chr(34) & projID & Chr(34) & " and [Volume Answers SC].Period = " & Chr(34) & j & Chr(34) & ";"
Set myqdf = currentdb.CreateQueryDef("update1", sqlstring)
DoCmd.OpenQuery "update1"
DoCmd.Close acQuery, "update1"
currentdb.QueryDefs.Delete "update1"
DoCmd.Close acQuery, "append1"
Next
rstd1.MoveNext
Next
i've cut this bit out to show how i'm trying to get the result of a query out into a variable and look
if anyone can help speed this up i'd be sooooo greatful
thanks
Matt