• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 202
  • Last Modified:

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

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
spoowiz
Asked:
spoowiz
  • 6
  • 6
1 Solution
 
___XXX_X_XXX___Commented:
because of this line:

txtStatus.Text = txtStatus.Text & vbCrLf & str


Remove it and try again
0
 
___XXX_X_XXX___Commented:
If no such slowing occurs, replace it with :

txtStatus.SelStart=Len(txtStatus.Text)
txtStatus.SelText=vbCrLf & str
0
 
spoowizAuthor Commented:
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
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
___XXX_X_XXX___Commented:
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
 
spoowizAuthor Commented:
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
 
spoowizAuthor Commented:
Another thing... the msAccess database table I'm opening (lstgSrc) is a linked table from msAccess to a .dbf (dbase) file.
0
 
dfiala13Commented:
do you have an index on the ID column of your Access table?  
0
 
spoowizAuthor Commented:
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
 
___XXX_X_XXX___Commented:
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
 
spoowizAuthor Commented:
same.
0
 
___XXX_X_XXX___Commented:
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
 
spoowizAuthor Commented:
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
 
___XXX_X_XXX___Commented:
Good luck !
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 6
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now