Solved Controlling Forms

Weekleyba

Registered User.
Local time
Today, 09:18
Joined
Oct 10, 2013
Messages
593
I have a database that opens with a main form (#1).
From the main form, the user can click to open form #2.
From #2 you can open form #3 or form #4.
From #3 you can open form #4 likewise from #4 you can open #3.
All of these stack on top of one another.

How do I keep the most recently opened form on top until it is closed?
Note, you can see some of other forms behind the most recent form.
This causes a problem since the user can select the form underneath, which I need to avoid.
 
It appears is I use Modal for forms #2, #3, & #4 it seems to work.
Does seem to fall in line with definition of Modal, as it's suppose to always keep focus.
I guess when you open another form from a command button on the a modal form, it allows it.
Is this a good way to do this?
 
It is good if it does what you wanted. I doubt that it would break anything. Note that a side effect of this is that when the modal form closes, the previous form (which is also modal) takes over. Which means you have to "unstack" the forms in the reverse order you stacked them. This is the behavior of a FIFO (first in first out) list. If that is what you wanted then leave it as-is.

If you want something different, ask us and describe what you really wanted.
 
I almost never allow multiple forms to be open/visible at one time. If you want to allow the user to go forward and backward through nested forms, you might use a technique I sometimes use.

FormA opens FormB and in the openargs passes its own name - Me.Name. and hides itself - Me.Visible = False

When FormB closes, it checks the Me.OpenArgs. If it is not null, it opens that form. If it is null, it opens the menu/switchboard. I have I

If FormB opens FormC, and in the openargs passes its own name - Me.Name and hides itself - Me.Visible = True

etc.

I have one app that goes four deep but most only go one or two deep.
 

Attachments

Thanks Pat! That's great.
I didn't see this for some reason but will definitely use this.
 
Hi Pat
For info, there is an error in the Form_Unload event of each form. The code says FormMenu but the actual form is called frmMenu
 
Colin, I'm not getting an error??
I do not get an error either but all Formx except for frmMenu have ???
Code:
Private Sub Form_Unload(Cancel As Integer)
        If IsNull(Me.OpenArgs) Then
            DoCmd.OpenForm "FormMenu", , , , , acWindowNormal
        Else
            DoCmd.OpenForm Me.OpenArgs, , , , , acWindowNormal
        End If
End Sub
 
Last edited:
You won't get an error but the open args part doesn't work as intended.
Change all occurrences of FormMenu to frmMenu to see it working 100%. Or rename that form!

Modified version attached
 

Attachments

Sorry. I figured it out. Thanks again. No one has noticed that in NINE years:)
 
I didn't notice it at first either as the main chaining part worked perfectly.
Someone recently pointed out a similar error in one of my apps that I first uploaded around 2008!
 

Users who are viewing this thread

Back
Top Bottom