Keep Two Modal Dialog Boxes In Correct Order?

J

Jay Chan

I would like to know how I can keep one modal dialog box on top of
another modal dialog box in the correct order.

I have a main-form with a button on it. When the user clicks at the
button, I will launch a modal dialog box (another form) on top of the
form. The modal dialog box also has a button on it. When the user
clicks at this button, I will launch yet another modal dialog box (yet
another form). This is like this:

Main-Form --> Modal-Dlg-1 --> Modal-Dlg-2

Obviously, I want Modal-Dlg-2 on top of Modal-Dlg-1, and Modal-Dlg-1
on top of Main-Form. But somehow, I see that Modal-Dlg-2 is on top of
Main-Form, and the Main-Form is on top of the Modal-Dlg-1. When the
user closes Modal-Dlg-2, Modal-Dlg-1 will resume back on top of
Main-Form. This is not a big problem. But this is kind of
dis-orienting. How can I fix this problem?

Currently, I manage Main-Form, Modal-Dlg-1 and Modal-Dlg-2 in this
ways:

- My start-up form pre-loads them in the order of Modal-Dlg-2,
Modal-Dlg-1, and Main-Form, and keep the modal dialog-boxes hidden:

DoCmd.OpenForm "frmModalDlg2"
Dim frmModalDlg2 As Form_frmModalDlg2
Set frmModalDlg2 = frmGetFormObj("frmModalDlg2")
frmModalDlg2.Visible = False

DoCmd.OpenForm "frmModalDlg1"
Dim frmModalDlg1 As Form_frmModalDlg1
Set frmModalDlg1 = frmGetFormObj("frmModalDlg1")
frmModalDlg1.Visible = False

DoCmd.OpenForm "frmMain"

Here, frmGetFormObj() is a function to point a form object to the
form that has alrady been loaded.

- When the user clicks at the button in Main-Form, I will launch
Modal-Dlg-1, like this:

Private Sub cmdShowModalDlg1_Click()
Dim frmModalDlg1 As Form_frmModalDlg1
Set frmModalDlg1 = frmGetFormObj("frmModalDlg1")
frmModalDlg1.vSomeParameter = ...
frmModalDlg1.Visible = True
Call frmModalDlg1.DoThingToPrepareDlg
Set frmModalDlg1 = Nothing
End Sub

- Likewise, when the user clicks at the button on Modal-Dlg-1, I
will launch Modal-Dlg-2, like this:

Private Sub cmdShowModalDlg2_Click()
Me.Modal = False

Dim frmModalDlg2 As Form_frmModalDlg2
Set frmModalDlg2 = frmGetFormObj("frmModalDlg2")
frmModalDlg2.vSomeParameter = ...
frmModalDlg2.Visible = True
Call frmModalDlg2.DoThingToPrepareDlg
Set frmModalDlg2 = Nothing
End Sub

These are all the relevant codes related to opening the main-form and
the modal dialog boxes. There are other custom events involved. But
they are only relevant when the user is closing the dialog boxes, not
when the user is opening the dialog boxes. Therefore, I don't mention
them here.

Please help me to find a way to get the "this-on-top-of-that" problem
fixed.

Thanks.

Jay Chan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top