Solved

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

Posted on 2004-03-27
13
190 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
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MsgBox 2 55
Can we place a tooltip on the actual vb6 form 5 42
Create Files based on Cell Values in a Range in Excel 12 40
Formula problem with Excel attachment 6 27
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
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…

809 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