Solved

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

Posted on 2004-03-27
13
194 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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
 
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

689 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