Combo box determine what sub-form to display (1 Viewer)

Jack_hardy10

New member
Local time
Yesterday, 17:43
Joined
Jun 17, 2019
Messages
1
Hi, hope some one can help.

I have a main form which contains a combo box (combo161) I would like either of the 4 option in this combo box to determine what subform is then displayed. The options in the combo box are 1,2,3,4 and the sub forms are called subform1, subform2, subform3, subform4. what code do I need to use?

Thank you
 

June7

AWF VIP
Local time
Yesterday, 16:43
Joined
Mar 9, 2014
Messages
5,470
Why not just use a tab control and have all 4 subforms installed, one on each page. Then user can just click on page tab to use subform.
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 01:43
Joined
Jul 9, 2003
Messages
16,280
Are they Identical?
If the sub forms are identical in structure, then you would be far better off changing the record source of the sub-form.

Switch the Forms
However if you indeed have differently structured forms, then it is quite easy to switch in and out the different sub-forms.

"Sub-Form Window"
A subform is not actually presents on your main form, the subform actually exists within a subform subreport/control which I generally referred to as a "Sub-Form Window".

"SourceObject"
This subform/subreport control has a property I believe from memory is called "SourceObject". You can change this source object with VBA. In other words point it at a different form and then that form will be shown within the subform/subreport control.

Parent/Child Relationship
Now one thing to watch out for is that if your forms are not similar, it is then likely that they will have different Fields linked to the main form. The field linking is controlled by a parent/child relationship stored within the subform/subreport control. This parent child arrangement is also modifiable with VBA code.

Example - Time Management Matrix
There's an example on my Nifty Access website called the Time Management Matrix (Stephen Covey) which demonstrates the use of four sub forms to create the Time Management Matrix. (It actually utilises one form four times)

Get it for FREE!
Click on this link:- https://gum.co/TimeManMatrix to download the Time Management Matrix, an example that demonstrates how to switch in and out sub-forms, and how to change the sub-forms properties, for example its record source. You can download the time management matrix subform example from here:- https://gum.co/TimeManMatrix To get it for FREE use the Coupon Code:- 95r2296

It's "HOT" I need a Beer!

Alternatively don't use the coupon code and buy "Uncle Gizmo" a coffee! ( I might have a beer!)
 
Last edited:

Gasman

Enthusiastic Amateur
Local time
Today, 01:43
Joined
Sep 21, 2011
Messages
14,260
I believe you need to set the source object for the subform control after testing the value of the combo box.
If however you brought the form name in as another column, then you would not even need to test the value.?

HTH

Code:
Me.sfrmEmails.SourceObject = "cfrmEmails"
 

Users who are viewing this thread

Top Bottom