Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Technique/Code to Stop Execution

Status
Not open for further replies.

tbw22

Technical User
Sep 11, 2006
1
CA
Hello,

Am wondering what is your approach to coding so that, for example, in my code I am using ADO to populate a recordset...if the query is taking too long, I would like to be able to just press the Escape key, and it cancels the recordset execution process.

What's the syntax to cancel the ADO's data pulling/querying?

 
tbw22,
Create a global variable in your module ([tt]blnStopRunning[/tt]?) and set it to False when your routine starts, then use a button on a form or a shortcut key to set the variable to True if you want to quit your routine.

Then in your routine add something like:
Code:
Public blnStopRunning as Boolean

Public Sub [i]YourRoutine[/i]()
blnStopRunning = False
...
DoEvents
If blnStopRunning then
  'go to your exit routine here
End If

To speed the whole process up you may want to add the code to only check every n records:
Code:
If Recordset.RecordNumber Mod [i]n[/i] = 0 Then
  DoEvents
  If blnStopRunning then
    'go to your exit routine here
  End If
End If

Hope this helps,
CMP

[small]For the best results do what I'm thinking, not what I'm saying.[/small]
(GMT-07:00) Mountain Time (US & Canada)
 
Hi CautionMP

I have used that approach when I have some sort of loop going on...where it's a repetitive cycle.

The current situation is that I'll have code like this:

Code:
[line 1]  Dim rs As ADO.Recordset

[line 2]  Set rs = New ADO.Recordset

[line 3]  rs.Open [sql statement], bla, bla, bla

Once line 3 goes, there's no turning back. Either it completes, times out, or the connection returns an error.

The situation I want to cover is the first one; once the statement is executed to get the data, I'd like to give the user the opportunity to change his/her mind in case the query takes to long to run, so I want to be able to cancel line 3.

Thank you for input.
 
tbw22,
Ohhh, I see. Have you tried the [tt]FetchProgress[/tt] event?

Support.Microsoft.com: How To Use the ADO FetchProgress and FetchComplete Events

I've never tried it but it looks like it might be a workable solution.

CMP

[small]For the best results do what I'm thinking, not what I'm saying.[/small]
(GMT-07:00) Mountain Time (US & Canada)
 
I'm looking into this, thanks for the information CautionMP!
 
randy700,

Ctrl+Break would not be available once you're in production mode...unless I'm mistaken.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top