This
DoCmd.OpenForm fnew, , , , , acDialog
Doesn't seem to stop code execution for some reason. Is it because I'm calling the function that has this method from another function and that is messing it up? E.g.
func1
<code>
Call func2
<func2 code>
DoCmd.OpenForm fnew, , , , , acDialog
<back to func1 code that executes even though i dont want it to until the form closes>
With
acDialog
as theOpenForm
WindowMode parameter, your calling code should not continue until the form is closed.It should not matter that
OpenForm
takes place in another procedure called from your code. In this example, when runningfunc1
, theMsgBox
is not displayed until the form closes.Note that code operates as described as long as the form is not already open. If it's open in Design View, calling
OpenForm
only switches it to Form View without applyingacDialog
. If open in Form View, nothing happens, which meansacDialog
is not applied then either.If you want to guarantee that
acDialog
is applied, make sure the form is closed before callingOpenForm
...I struggled with this one for ages until I realised that the acDialog setting does nothing if the form is open in design view when the code is run. It does actually pause the code from the opening procedure when run in normal use (i.e. no one's trying to design anything). If you want to test this behaviour, create a form "zzTestForm", and run this from a module: