Multiple SubForms (1 Viewer)

JPR

Registered User.
Local time
Today, 14:27
Joined
Jan 23, 2009
Messages
192
Hello,

I have created a form with several cmd buttons which should open different subforms.
I would like that these subform open only on the click event and once closed either close down or are hidden.

All the subform should have a specific position, in a sort of a frame (in my sample Box3).

I am attaching a very simple db sample to give you a better idea. For my convenience I have set the open form as popups.
Thank you for your help.
 

Attachments

  • TEST.zip
    64.3 KB · Views: 79

isladogs

MVP / VIP
Local time
Today, 22:27
Joined
Jan 14, 2017
Messages
18,209
There are two possible approaches. In either case remove the popup status.
1. Add both subforms to your main form in the required location and set hidden (visible =false)
On button click, set one subform visible and hide the other
2. Add an empty hidden subform to the main form. On button click, set the subform source object to one of your forms and make it visible
 

JPR

Registered User.
Local time
Today, 14:27
Joined
Jan 23, 2009
Messages
192
Thank you .
I have created an empty subform, named it Test and the following code the the form Load event: Me.SubTest.visible = False.
I have then added the following code to the the cmd buttons:

Me!SUBTEST.SourceObject = SUBCLIENTS
Me.SUBTEST.Visible = True

Me!SUBTEST.SourceObject = subInfo
Me.SUBTEST.Visible = True

Sorry but still not working as I do see the SubTest but it's empty. Thank you
 

isladogs

MVP / VIP
Local time
Today, 22:27
Joined
Jan 14, 2017
Messages
18,209
If your empty subform container is called Test, the syntax should be
Code:
Me.TEST.SourceObject = "SUBCLIENTS"
Me.TEST.Visible = True

Me.TEST.SourceObject = "subInfo"
Me.TEST.Visible = True
 

theDBguy

I’m here to help
Staff member
Local time
Today, 14:27
Joined
Oct 29, 2018
Messages
21,453
Hi JPR. Just curious, have you tried using a Navigation Form?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 14:27
Joined
Oct 29, 2018
Messages
21,453

isladogs

MVP / VIP
Local time
Today, 22:27
Joined
Jan 14, 2017
Messages
18,209
Navigation forms can work well as long as you don't need to make any significant changes to the default options.
I would caution against their use because they are relatively inflexible.
 

JPR

Registered User.
Local time
Today, 14:27
Joined
Jan 23, 2009
Messages
192
Hello,
just to give you an update. I have made a minor change to your code and it's now working great:

SubMaster is the empty subform.
SubSearch is the other subform that shows up (the source object) after the click event of my cmd button.

Please note that my db main form is named frmMenu and when it opens, it shows the empty Submaster.

Me.Submaster.SourceObject = "SubSearch"
Me.Submaster.Visible = True

I would now like to create a new cmdbutton on teh SubSearch form which unloads the Subsearch form leave the SubMaster visible on the frmMenu.

Thank you
 

isladogs

MVP / VIP
Local time
Today, 22:27
Joined
Jan 14, 2017
Messages
18,209
You can't unload a subform using a button on the subform itself.
However you could make the existing button on the main form dual purpose

SQL:
Private Sub cmdSearch_Click()

    Me.Submaster.Visible = True

If cmdSearch.Caption="Show SubSearch" Then
    Me.Submaster.SourceObject = "SubSearch"
    cmdSearch.Caption="Hide SubSearch"
Else
    Me.Submaster.SourceObject = ""
    cmdSearch.Caption="Show SubSearch"
End If

End Sub

Modify as appropriate
 

Users who are viewing this thread

Top Bottom