Avatar of colinasad
Flag for United Kingdom of Great Britain and Northern Ireland

asked on 

How can I interrupt a run through a recordset in Access VBA?

I am developing an Access "Project" (.adp) as a front-end to a SQL Server 2005 Express database.

In one of my Access forms I populate a recordset (perhaps a few thousand records) and step through it using the strategy shown in the attached code snippet.

I offer the user a "Stop" command button on the form so that they can (hopefully) stop the processing of the records. The "cmdStop_Click" procedure asks the operator if the really want to stop and sets "blnStop" to "True" if they do.

However, the run through the record set appears to suck up all of Access's processing power and seems to prevent anything else being acknowledged. In fact the "(Not Responding)" banner sometimes appears in my form's top border if I click on the "Stop" button. The run through the recordset does complete but I do not get my "cmdStop_Click" dialogue message.

Can anyone tell me why my run through the recordset is so "greedy" and how I can interrupt it?
blnStop = False
For intStkCounter = 1 To intStkLines 
     With rsTarget
Body of code
      End With ' with rsTarget
      If blnStop Then intStkCounter = intStkLines
Next intStkCounter

Open in new window

Microsoft Access

Avatar of undefined
Last Comment

8/22/2022 - Mon