Display different subforms based on combobox selection??

A

Amit

Hi,

I would like to open different subforms from a mainform,
based on the value selected by the user. Is this
possible?? Any help will be appreciated.

FormA has a combo-box with 2 values - 1 & 2. If user
selects '1', then subform1 is opened. If user selects '2',
then subform2 is opened.

TIA.

-Amit
 
S

Sandra Daigle

Hi Amit,

This is quite possible - here's some sample code - replace 'sfrmMySub' with
the name of the subform control on your main form and replace 'MyCombo' with
the name of your combo box. Also, I used a select Case statement though this
could also be done with a plain old If-then type statement.

This also doesn't take into account that you might need to change linking
fields - let me know if you also need help with this.

Select Case Me.MyCombo
Case 1
Me.sfrmMySub.SourceObject = "Subform1"
Case 2
Me.sfrmMySub.SourceObject = "Subform2"
End Select
End Sub
 
J

Jim/Chris

If you only have two subforms why not add two tabs to your
main form and put 1 subform under each.

Jim
 
S

Sandra Daigle

Not necessarily,

Open the main form, click once on the subform to select the subform
control - look under the Other Tab for the name property. This is the name
of the subform control. The form which is specified in the SourceObject of
the subform control may have a different name (which is the name of the form
object as seen in the database window).

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.

Hi Sandra,

Thanks for your suggestion. Is the subform control in the
main form same as the name of the subform?

-Amit
-----Original Message-----
Hi Amit,

This is quite possible - here's some sample code - replace
'sfrmMySub' with the name of the subform control on your main form
and replace 'MyCombo' with the name of your combo box. Also, I used
a select Case statement though this could also be done with a plain
old If-then type statement.

This also doesn't take into account that you might need to change
linking fields - let me know if you also need help with this.

Select Case Me.MyCombo
Case 1
Me.sfrmMySub.SourceObject = "Subform1"
Case 2
Me.sfrmMySub.SourceObject = "Subform2"
End Select
End Sub


--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.
Hi,

I would like to open different subforms from a mainform,
based on the value selected by the user. Is this
possible?? Any help will be appreciated.

FormA has a combo-box with 2 values - 1 & 2. If user
selects '1', then subform1 is opened. If user selects '2',
then subform2 is opened.

TIA.

-Amit

.
 

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