Question:
In a simple loop on a form with a Cancel Button:
DoHere I want to Check to see if a user pushed a cancel button(Cancel Property is set to true)(While in loop can’t get focus to Cancel Button to see if it was pushed. Setting focus to it does not work. There must be a simple way to trap for this) If Cancel is Pushed, Exit LoopLoopAny info would be appreciated.
Answer:
What I would do is from the Cancel_Click event, set a flag to True. At the bottom of your loop put a DoEvents statement. This frees up the processor to check for things like button clicks, etc. At the top of your loop, check the flag and if True, exit the loop. Let’s say your flag is global and is called gintCancelFlag. Pseudo-code looks something like this:
DoIf gintCancelFlag = True Then Exit Do’In here you’d put the code the loop is supposed to be doing.DoEvents () ‘note that the () is necessaryLoop