Exit a procedue by a keystroke in vb 6.0

Posted on 2009-04-14
Medium Priority
Last Modified: 2013-12-26
I have a for loop in one of the command button code of the vb applicatoin. Is there a way I can exit this for loop my hitting some keys..I am looking for key_stroke process to end a for loop
Question by:Aiysha
1 Comment
LVL 22

Accepted Solution

danaseaman earned 2000 total points
ID: 24140462
Try this. Uses Do/Loop but could be For/Next:

Option Explicit
Dim bEscape             As Boolean
Private Sub Command1_Click()
   Dim i                As Long
      If bEscape Then
         bEscape = False
         Debug.Print "Exiting loop"
         Exit Do
      End If
End Sub
Private Sub Form_KeyPress(KeyAscii As Integer)
   If KeyAscii = 27 Then
      bEscape = True
   End If
End Sub
Private Sub Form_Load()
   Me.KeyPreview = True
End Sub

Open in new window


Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

624 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