Regarding the Visible property, you can use code (in a comman button, for
instance) on a form to hide that form (which is how you would proceed with a
Dialog form), or you can use it from another form using the syntax I
described. If you hide the main form and open a dialog form, you need to
make the main form visible from the dialog form. In the examples below I
added message boxes to help show the timing. They are not necessary. In the
main form:
Me.Visible = False
DoCmd.OpenForm "frmDialog", , , , ,acDialog
MsgBox "Back in business"
The second line could be:
DoCmd.OpenForm "frmDialog",WindowMode:=acDialog
In the Dialog form:
DoCmd.Close acForm,Me.Name
Forms!frmMain.Visible = True
MsgBox "Dialog form closing"
or, if you just want to hide the form:
Me.Visible = False
Forms!frmMain.Visible = True
In the main form, the form is hidden with the first line of code, then the
dialog form is opened with the next line of code. Code execution halts, as
John succinctly observed. Note that you need to hide the form before opening
the dialog form. Code execution continues even though the form is hidden,
but if the first two lines of code are reversed the Visible line of code will
not execute until the dialog form is closed or hidden.
In the dialog form (or any form) you can use Me.Name to close the form, or
you can use the name of the form in quotes:
DoCmd.Close acForm,"frmDialog"
Again, the code execution continues after closing or hiding the dialog form,
so the next line of code (and the rest of the procedure) runs. If you have
the message box code, you will first see the message "Dialog form closing",
then "Back in business". The code in the dialog form is still running, so
whatever is in the code comes before the code in the main form. Once the
dialog form code is stopped, focus returns to the main form, and the message
appears. In practice the dialog form will be hidden (or close), the main
form will become visible, the dialog form code will continue (showing you the
message box), and the main form code will resume where it left off (showing
you another message box).
Again, the message boxes are for illustration only. They can be useful for
sorting out timing issues.
I expect it is clear that frmMain and frmDialog are generic form names that
would be replaced by the actual form names, but I'll mention it anyhow.
Hi John,
I see Bruce had a go at explaining for me which I appreciate but your brief
explanation was more the points I'm trying to get to understand. Maybe what's
confusing the issue for me was that at my first go with a dialog form I got
the calling form to continue code execution however the control was not
returned to the calling form.
By that I mean that buttons to execute other coded queries would not
function but I could close the form manually & the button in the calling
forms footer which closes the database did work. The calling form has tabs &
they wouldn't function either. So in essence I'm trying to understand the
timing & transfer of control using a dialog form & the effect of .visible &
which form should have those instructions. At the moment it's a bit of "as
clear as mud" as my dad used to say.
Thanks for helping
That sounds simple enough but is not quite the case since the one form is
opened in dialog mode.
[quoted text clipped - 5 lines]
Execution will resume when either of two things happen: the dialog form is
closed, or its Visible property is set to False.
--
.