We help IT Professionals succeed at work.

Canceling excution of all code when end user select x at top of form

Juan Ocasio
Juan Ocasio asked
on
Hello all:

I have two forms (MS Access 2010).  The main form allows an end user to select certain materials.  Once they select an item and then press 'Process', it the material has serial numbers, it displays the second form (acDialog), so the end user can select the serial numbers they're processing.  What I would like to happen is if an end user clicks the x at the top of the second form (the serial number selector), I want all execution to stop.  I thought if I create an Err object it would do that, but it throws the error and then continues execution on the main form.  Is there a way to completely stop execution of the code?

Many thanks!

Juan
Comment
Watch Question

Jim Dettman (EE MVE)President / Owner
Fellow 2019
Most Valuable Expert 2017
Commented:
1. Remove the close button.
2. Add a hidden control and default it to "OK"
3. Add your own cancel button.
4. When they click it, set the hidden control to "Cancel", then hide the form.
5. Also give them an "OK" button, which just hides the form.


Execution will resume in the calling code where you can check how they exited by looking at the hidden control.
Then close the form there.

Jim.
Dale FyeOwner, Dev-Soln LLC
Most Valuable Expert 2014
Top Expert 2010

Commented:
I prefer not to use the close button of the popup (I actually disable it) and instead use a Cancel button.

One of the neat things about the acDialog value in the WindowMode is that the code on the main form will pause until you have closed (or hidden) the popup form;  the key here is "or hidden"!  The way I use this is to place a cancel button on the popup form and hide the form in when that button is clicked.  I then use code like the following in the main form.

docmd.OpenForm "frmPopup", acNormal, , , ,acDialog
if currentproject.allforms("frmPopup").isloaded then
    docmd.close acform, "frmPopup"
    Exit sub
endif
'otherwise, continue
Dale FyeOwner, Dev-Soln LLC
Most Valuable Expert 2014
Top Expert 2010

Commented:
Jim, I noticed you looking at the post before I hit send, but did not think to refresh the page before I did so.
Jim Dettman (EE MVE)President / Owner
Fellow 2019
Most Valuable Expert 2017

Commented:
no problem and Juan is sure he has a good answer now<g>

Jim,
Juan OcasioApplication Developer

Author

Commented:
Thank you both for your input.  How do you set the dialog's hidden prop to true?  I can't seem to find the correct property.

Thanks!

Juan
President / Owner
Fellow 2019
Most Valuable Expert 2017
Commented:
You just hide the form:

 Me.visible = False

Jim.
Juan OcasioApplication Developer

Author

Commented:
I got it.  Thanks for both of your help!
Juan OcasioApplication Developer

Author

Commented:
I hope I've awarded the point equally.  It appears to be a bit different.  You both were extremely helpful!

Thanks again!

Juan