How to execute code on an escape? Help.

back2basic

Registered User.
Local time
Today, 13:57
Joined
Feb 19, 2013
Messages
113
Hello, my form is opened in "add" mode using a switchboard. The first field of the form calls a VB Sub which makes some necessary changes (based on user responses) in some foreign tables.

If the user "escapes" while entering data in the 2nd or 3rd fields, of course after the VB module has closed in first field, I need to catch it and execute code to reverse the changes made.

On error does not work. Anyone know how to execute code on an escape?
 
Have you tried the form's On Undo event

Thank you this works. I appreciate it. I hate to ask this but its been a while since I have programmed. I feel this is going to get complicated.... but I really hope not.

Please allow me to explain: The form has 4 fields, in which of course the user can cancel at anytime.

The first field which is making the changes to the foreign table is bound to a combo box cboMaterial_ID as declared:

Code:
Private Sub cboMaterial_ID_BeforeUpdate(Cancel As Integer)

The forms On Undo event runs but does not see the variables of the combo box. I suspect I need to make some global or public declarations ( please help) but is the combox box pointer no longer valid after I have left the bound field?

Thank you
 
The forms On Undo event runs but does not see the variables of the combo box.
Not sure what you mean by this, but I think you mean that when the form's Undo event runs the selection first made the user is lost, so you have no criteria to reverse the changes that were made in code when the user first made the selection. If that is right then perhaps you could declare a variable and asign the value of the combo box to it in the after update event of the combo box. You may also need code to check deal the situation when a user changes the selection made in the combo box.
 
Not sure what you mean by this, but I think you mean that when the form's Undo event runs the selection first made the user is lost, so you have no criteria to reverse the changes that were made in code when the user first made the selection. If that is right then perhaps you could declare a variable and asign the value of the combo box to it in the after update event of the combo box. You may also need code to check deal the situation when a user changes the selection made in the combo box.
All of the above is correct
I did declare a variable as public in the global declarations section
Code:
public QTY_Requested as integer
.
Wow, worked it out myself....Should have known. It all works but the only problem now is I can't see the value of the public variable in the watch box. The calculations are all working so the variable must be valid?

.... Any suggestions?
 
Last edited:
It all works but the only problem now is I can't see the value of the public variable in the watch box.
What is the "Watch Box"?
Why do you need to see the value of the variable?
 
What is the "Watch Box"?
Why do you need to see the value of the variable?

It is an Expression in the watch list....Sorry should have been more clear. Need to see it because I'm debugging.
 
You can always use the line:
Debug.Print NameOfYourVariable
anywhere in your code. The value will then be shown in the Immediate Window.
 
Yes, good to know thank you. Something strange is happening. Hopefully you can explain:

When I insert a break point and step through the Undo event procedure, it all works fine without error; However, when I remove the break point and run real-time, I get a run-time error '3059'.
" Operation cancelled by user".
and the code stops....Do you know why?
 
Last edited:

Users who are viewing this thread

Back
Top Bottom