Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with speeding up code execution

Status
Not open for further replies.

whatever9987654

Technical User
May 5, 2006
2
US
Hey Guys,

I'm looking to speed up this code, it runs 3 queries to calculate data and append to each row. It runs slower as it progresses, the only thing I can think of is changing the 'For Next' to a 'For Each Next' statement. On a recorset of 2000 records it runs approx 2 records per second then slows down to 1 record a second, and so on. Anyway, I'm only a junior coder and would appreciate any help. Thanks guys!(and gals)

-MS


For Rcd = 30 To total_records Step 1

current_id = rs_id.Fields("id")

Set rs_value = db.OpenRecordset("SELECT NMBR as
current_number FROM data WHERE id
=" & current_id)

current_number = rs_value.Fields("current_number")

Set rs_sum = db.OpenRecordset("SELECT SUM(NMBR)
as current_sum FROM data WHERE id IN
(SELECT TOP 30 id from data WHERE id
<= " & current_id & " ORDER BY id
DESC)")

current_sum = rs_sum.Fields("current_sum")

current_average = current_sum / 30

current_difference = current_number -
current_average

db.Execute ("UPDATE data SET C_SUM=" & current_sum
& ", C_AVG=" & current_average & ",
C_DIF=" & current_difference & " WHERE
id=" & current_id)

rs_id.MovePrevious
Next Rcd
 


Hi,

FYI...

How Can I Make My Code Run Faster? faq707-4105

Then post back.

Skip,

[glasses] [red]Be Advised![/red] A chicken, who would drag a wagon across the road for 2 cents, is…
POULTRY in motion to PULLET for a PALTRY amount! [tongue]
 

Skip,

Thanks for the info, however Application.screenupdating does not seem to be a valid call in MS Access. As far as the other areas of the statement, I'm not sure how this differs from mine except for the case statement. Any help on this would be appreciated.

MS
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top