I have an application using multiple Forms, all unbound. The main Form enables users to select which other Forms they want to use, only one at a time, all Modal. I don't want users to close Access via the red Close X top right, only from the main menu Form, which records certain data when closing.
To achieve this, I declared a public variable at Form level in the main 'menu' Form:
Obviously this is False by default, and only when the main Form is closed via a Command Button is it set to True first. In the main Form, the code in the Unload event is:
Now this works fine when only the main Form is open. However, if a second Form is open and the user clicks the application close x top right, the code does work, the application does not close BUT I can not close the second (Modal) Form by clicking the Close Command Button. I set the close Command Button's Cancel property to True, so pressing the Esc key does close the Form, but I don't understand why this is the case. There is a TextBox in one of the Forms opened after the main Form, and when the user clicks the X top right, despite subsequently clicking the Close Command Button to no effect, it is still possible to type in the TextBox, so the Form must have focus.
I have tried using DoCmd.CancelEve nt rather then Cancel = True, to no avail. Any ideas as to what is going on would be welcome.
To achieve this, I declared a public variable at Form level in the main 'menu' Form:
Code:
Public fOKClose As Boolean
Code:
If fOKClose = False Then Cancel = True
I have tried using DoCmd.CancelEve nt rather then Cancel = True, to no avail. Any ideas as to what is going on would be welcome.
Comment