Stop Macro with VBA on Pop Up Form

Frank123

Registered User.
Local time
Today, 02:36
Joined
Jun 29, 2016
Messages
31
Hi,

I'm new to VBA and this sounds simple (I think). I have a pop up form that is opened in dialog mode by a macro in Access 2010. The macro also performs other steps after other buttons on the form are pressed. I then placed a "cancel" button on the pop up form to close everything out. I used "Exit Sub", "DoCmd.close", and "End", which closes the form, but the macro still continues to run to its end. I need the "cancel" button to stop and exit the macro, and then close the form. What am I missing here? I cannot seem to find any vba that will do that. Can someone please help me. :confused:
 
If you call a modal form the code on the calling form is paused until the modal form returns control to it. I'm pretty certain this will be the same for macros as well.
I personally wouldn't mix macro's and VBA, as it's very much harder to easily see what is going on.

Also a Cancel button would imply to me that you will cancel the action on the pop up not simply close the form.

Convert the macro's to VBA and the post back the code that is giving you the problem, it's not easy to debug macro's without a ton of photo's or you uploading the database.
 
If you call a modal form the code on the calling form is paused until the modal form returns control to it.

I think this would be great as then you might be able to make a form act like a message box but it doesn't seem to be true. In the attached database when the follow code is run the msgbox appears right after the frmModalForm form is open. The code doesn't pause until the form is closed if that's what you meant. frmModalForm is both set to modal and popup.


Code:
DoCmd.OpenForm "frmModalForm"
MsgBox "This is after the form open"
 

Attachments

To get calling code to pause while a popup form is open, use the acDialog parameter in DoCmd.OpenForm, like...
Code:
DoCmd.OpenForm "Form1", , , , , acDialog
MsgBox "This code doesn't run until Form1 is closed or hidden."
 
To get calling code to pause while a popup form is open, use the acDialog parameter in DoCmd.OpenForm, like...
Code:
DoCmd.OpenForm "Form1", , , , , acDialog
MsgBox "This code doesn't run until Form1 is closed or hidden."
Thank you and Minty. This is very useful information.
 
Yes, this is a powerful mechanism to control the user's options, for sure, and I use it very commonly as a wizard pattern for eliciting complex validated data from a user.

I remove the close button from the wizard form in design view, then open it with the acDialog switch in DoCmd.OpenForm. The modal wizard then elicits and validates user input, and when the user hits my OK or Cancel buttons I simply hide the wizard form, and the calling code can read the completed validated result. Then the calling code closes the hidden wizard form when it's done.
 

Users who are viewing this thread

Back
Top Bottom