Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 217
  • Last Modified:

Access VBA & ADO speed issue

Hi

I am running the following ADO code but the procedure is taking over 10 minutes to finish.

Basically it opens a first recordset to get a user id.  The user id is then used as criteria for a sql string which opens a second recordset based on membership records.  Various tests are performed on the records in the second recordset before this recordset is closed and the next user id is got from the first recordset etc etc

The User table has approx 15000 records whilst the Membership table has approx 27000.

The code works but is slow.  I am fairly new to ADO so my question is simply is there any way I could speed this up by using different cursors or methods

Many thanks

Ken
objcon.Open CurrentProject.Connection
 
        objrst.Open "Users", objcon, adOpenKeyset, adLockOptimistic
 
        
        With objrst
 
        Do Until .EOF = True
 
            lonCurrID = !UserID             
 
          	strSQL2 = "SELECT UserID, StartDate, EndDate, GroupID, TypeID from Membership where UserID = lonCurrID"
 
               objrst2.Open strSQL2, objcon, adOpenKeyset, adLockOptimistic
                   
                        With objrst2
                        
                            	Do Until .EOF = True
                              
                        		select case
 
				<do various tests>
 
			end select                     	    	
                                    
                                	.MoveNext
                            Loop
                        
                        End With
            
                        objrst2.Close
 
            .MoveNext
            Loop
 
        End With
 
        objrst.Close
 
        objcon.Close

Open in new window

0
kenabbott
Asked:
kenabbott
2 Solutions
 
TextReportCommented:
Ultimately using SQL would be quicker rather than the way you are doing but it depends on what the TESTS are that you are doing. For example a UPDATE statement with the criteria required would be quicker than walking through the records.
You should be able to do this by creating a single recordset and looping through that rather than 2 recordsets

Hope this makes sense and you can expand on the tests that you are carrying out.

Cheers, Andrew
0
 
Rey Obrero (Capricorn1)Commented:
try using the recordcount instead of testing the EOF

dim recCnt1 as integer, recCnt2 as integer,x,j

objrst.movelast
recCnt1=objrst.recordcount
objrst.movefirst

for x=1 to recCnt1




next x


i used this in DAO, and prove to run faster than using .EOF


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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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