Forcing an Open Form Closed in VBA

Sorrells

Registered User.
Local time
Today, 17:06
Joined
Jan 13, 2001
Messages
258
Gentlefolk,

I have a form (A) that when a specific field is completed, a DLOOKUP is made to determine if the data value entered is in a table. If is it not, I hide form A and open another form (B) to add the data into another table.
Being a nice guy, in this form B, I give the user a chance to return to the main menu in case they have gone deeper than they intended. If they take this option (a command button), I attempt to close form A then B.
Unfortunately, the control that I left form A on has both AfterUpdate and LostFocus VBA code. When closing A from B, these events are executed. Rats!
Can I unulateratly close a hidden form from another form such that it cannot execute any non-executed code.
My thanks in advance for any help. Sorrells
 
I know of no way of stopping the events firing on closing the form, however.... you could include a global boolean variable in the events you want to stop such that..

if bCancelThisEvent then exit sub

is added to these events and then the variable can be controlled from other code or forms....Good Luck
 
PhilE,

Thanks for your comment. I have traditionally avoided global variables in fear of their great scope but after meditating your comments, did so. I created a global flag on whose value I could either skip the control's code or not. I then set the value for the flag under the command button to skip the code. I also had to set the flag when the form opened so that it had a value when the control was used.
I appreciate your thoughts!

Thanks, Sorrells
 

Users who are viewing this thread

Back
Top Bottom