Solved

Why is this loop slowing down as number of records are processed?

Posted on 2004-03-27
13
188 Views
Last Modified: 2010-05-01
This following code took 13 minutes!
The Label1 counter was fast in the beginning but as the loop progessed it slowed down to a crawl.
Why would this happen and how can i correct it?

lstgVC is a mySQL local database
lstgSrc is msAccess database

thanks
phil

    Do Until lstgVC.EOF
        inCnt = inCnt + 1
        Label1.Caption = inCnt & " of " & recCnt
        Label1.Refresh
        DoEvents
            lstgSrc.Open "SELECT id FROM Table1" _
                         & "WHERE id=" & lstgVC!ID, _
                         cnSrc, adOpenKeyset, adLockOptimistic
        If lstgSrc.RecordCount = 0 Then
            lstgVC!Status = "U"
            lstgVC!DeleteFlag = 1
            'lstgVC.Update
            lstgVC.CancelUpdate   <---------------------note that I'm not even doing an update
            outCnt = outCnt + 1
            txtStatus.Text = txtStatus.Text & vbCrLf & str
            txtStatus.Refresh
        End If
        lstgSrc.Close
        Set lstgSrc = Nothing
        lstgVC.MoveNext
    Loop
0
Comment
Question by:spoowiz
  • 6
  • 6
13 Comments
 
LVL 6

Expert Comment

by:___XXX_X_XXX___
ID: 10696027
because of this line:

txtStatus.Text = txtStatus.Text & vbCrLf & str


Remove it and try again
0
 
LVL 6

Expert Comment

by:___XXX_X_XXX___
ID: 10696031
If no such slowing occurs, replace it with :

txtStatus.SelStart=Len(txtStatus.Text)
txtStatus.SelText=vbCrLf & str
0
 

Author Comment

by:spoowiz
ID: 10696212
hi,
that's not it. i even commented it out and still slows down.
btw, lstgVC selection count is only 2900 records. By about 900 records into it starts slowing down. by 1200 records into it, it REALLY slow, maybe 3 to 5 records per second.
phil
0
 
LVL 6

Expert Comment

by:___XXX_X_XXX___
ID: 10696225
Ok , comment everythink between Do...Loop and keep only:

lstgSrc.Open "SELECT id FROM Table1" _
                         & "WHERE id=" & lstgVC!ID, _
                         cnSrc, adOpenKeyset, adLockOptimistic



Is problem occurs again ?
0
 

Author Comment

by:spoowiz
ID: 10696245
Good idea.
I took out basically everything but lstgSrc.open/close and it behaves the same.
I then took out the lstgSrc.open/close and takes no time to finish 2800 records.
So it must be the lstgSrc.Open stmt causing it.
I wonder why.
0
 

Author Comment

by:spoowiz
ID: 10696253
Another thing... the msAccess database table I'm opening (lstgSrc) is a linked table from msAccess to a .dbf (dbase) file.
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 12

Expert Comment

by:dfiala13
ID: 10696263
do you have an index on the ID column of your Access table?  
0
 

Author Comment

by:spoowiz
ID: 10696278
yes. the dbase file has an index on the ID field and opening it in design mode from msAccess shows that it it is indexed.
0
 
LVL 6

Expert Comment

by:___XXX_X_XXX___
ID: 10696292
Try change this:
lstgSrc.Open "SELECT id FROM Table1" _
                         & "WHERE id=" & lstgVC!ID, _
                         cnSrc, adOpenKeyset, adLockOptimistic

With this:
Dim rstRecordset As Recordset
.....
.....
Set rstRecordset=cnSrc.Execute("SELECT id FROM Table1 WHERE id=" & lstgVC!ID)

Keep other lines commented. Again same problem ?
0
 

Author Comment

by:spoowiz
ID: 10696302
same.
0
 
LVL 6

Accepted Solution

by:
___XXX_X_XXX___ earned 125 total points
ID: 10696319
Ok, in order to determine if this "link" between access and DBF causes your problem, you can try this code with other access database that is not "linked to" dBase file.

Create some MDB file with table named Table1 and field named id (also add other fileds that persist in original database file), populate with some fake data and execute your SQL query against it. Is there same problem ?
0
 

Author Comment

by:spoowiz
ID: 10696342
I re-wrote by inserting all the ID's from the dbase file to another msAccess TEMP table I just created and ran it. It finished in 13 seconds. Many repetetive calls to the dbase file seems to be the problem. Well, hopefully I need to do this in another place. The workaround is to use the temp file. Thanks.
0
 
LVL 6

Expert Comment

by:___XXX_X_XXX___
ID: 10696349
Good luck !
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Share codes 68 115
VBA loop through headers using value 3 48
Access 2016 VB code 9 86
Excel object stays open 19 65
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now