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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to gracefully stop running code

Status
Not open for further replies.

georgesOne

Technical User
Jul 2, 2004
176
JP
Hi All:

I use standard VBA filesearch code started by a form's command button to find files which may have been displaced. Sometimes the search takes very long and needs interruption (without producing a result), so that the user can move to a different record, or the like.

Thanks for any suggestion, georges
 
How are ya georgesOne . . .

Post your search code!

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Hi there,

Maybe you could adapt this (untested) code?

Code:
      Option Explicit
      Dim blnFlag As Boolean

      Private Sub cmdStop_Click()
      blnFlag = False
      End Sub

      Private Sub cmdStart_Click()

      blnFlag = True
      Do While blnFlag = True
      'Your COde here.
      DoEvents
      Loop
      End Sub

Remember- It's nice to be important,
but it's important to be nice :)
 
Hi Aceman1 and petrosky,

thanks for your interest. The code I use is as follows:

With Application.FileSearch
.NewSearch
.LookIn = "C:\"
.SearchSubFolders = True
.FileName = sFile

If .Execute() > 0 Then
... blah blah
End If
End With

Now, if I search in drive C as indicated this (the .Execute line) can take quite a while, even more so, if I search a drive/folder on the network.
My question: is there a possibility to stop the execution, once it has been started?... (I guess not...???)

Thanks, georges
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top