Can any one out there help me figure out how to to cancel a long process in the middle of a long loop by hitting the esc key in my VBA code. Any help on this matter would be much apprieciated.
Nope! When a user pressess the Esc key I want to provide them with an option to continue or quit and .rollback the process. I have my own Yes/No prompt.
This sample is really vague. Can someone give me more detail please? Remember I want this function to detect if the user hits the Esc key. Actually, any key would be better.
Sorry, I was just trying to give an overview. If you set the form to keypreview then the form will test for the key first before any control that has focus. Then if you set the form keydown event to test for the escape key and set the variable isCancel = true. Then in your loop add the
doevents
if( isCancel ) then exit sub
dim isCancel as boolean
Private Sub Form_Load()
Me.KeyPreview = True
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
'test if key hit is enter
if((KeyCode = 27) 'Esc Key)
isCancel = true
end if
End Sub
Hope this helps, or gets you going in the right direction.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.