Solved Controlling Forms (1 Viewer)

Weekleyba

Registered User.
Local time
Today, 14:32
Joined
Oct 10, 2013
Messages
586
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.
 

Weekleyba

Registered User.
Local time
Today, 14:32
Joined
Oct 10, 2013
Messages
586
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?
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 14:32
Joined
Feb 28, 2001
Messages
27,000
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.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 15:32
Joined
Feb 19, 2002
Messages
42,973
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

  • ChainingForms.zip
    182.6 KB · Views: 224

Weekleyba

Registered User.
Local time
Today, 14:32
Joined
Oct 10, 2013
Messages
586
Thanks Pat! That's great.
I didn't see this for some reason but will definitely use this.
 

isladogs

MVP / VIP
Local time
Today, 19:32
Joined
Jan 14, 2017
Messages
18,186
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
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 15:32
Joined
Feb 19, 2002
Messages
42,973
You're welcome:)

Thanks Colin. I'll fix it.
 

Gasman

Enthusiastic Amateur
Local time
Today, 19:32
Joined
Sep 21, 2011
Messages
14,046
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:

isladogs

MVP / VIP
Local time
Today, 19:32
Joined
Jan 14, 2017
Messages
18,186
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

  • ChainingForms_CR.zip
    96.7 KB · Views: 191

Pat Hartman

Super Moderator
Staff member
Local time
Today, 15:32
Joined
Feb 19, 2002
Messages
42,973
Sorry. I figured it out. Thanks again. No one has noticed that in NINE years:)
 

isladogs

MVP / VIP
Local time
Today, 19:32
Joined
Jan 14, 2017
Messages
18,186
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

Top Bottom