Solved

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

Posted on 2004-03-27
13
189 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
DO Loop not working 4 72
Excel VBA combine two working workbooks 8 46
VB error "Type mismatch" 2 49
Microsoft Access combo box help 2 38
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

910 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

23 Experts available now in Live!

Get 1:1 Help Now