Link to home
Start Free TrialLog in
Avatar of Juan Ocasio
Juan OcasioFlag for United States of America

asked on

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

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
SOLUTION
Avatar of Jim Dettman (EE MVE)
Jim Dettman (EE MVE)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Jim, I noticed you looking at the post before I hit send, but did not think to refresh the page before I did so.
no problem and Juan is sure he has a good answer now<g>

Jim,
Avatar of Juan Ocasio

ASKER

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
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I got it.  Thanks for both of your help!
I hope I've awarded the point equally.  It appears to be a bit different.  You both were extremely helpful!

Thanks again!

Juan