Magic subforms

djh

Registered User.
Local time
Today, 10:10
Joined
Jul 19, 2000
Messages
16
Is it possible to have different subforms pop up in a form depending on the choice of a list menu/combo box?

Thanks!
 
Yes; you could have them in different pages of a tab control and have a bit of code that selects the relevant tab depending on the choice...

or

you could just have them all superimposed on the form and selectively make them visible (I've seen this approach used but I think it's a bit messy)

If you give me a bit more of the specifics, I'll be better able to help.

Mike
 
Thanks Mike,

Would the code just be something like...

Code:
if MyComboBox = "X" then
Me!MySubformControl.sourceobject = "frmSubformX"
elseif MyComboBox = "Y" then
Me!MySubformControl.sourceobject = "frmSubformY"
endif

This is for a subform, but how would one control which tab is displayed? And where exactly would this event procedure be entered? Into a "After Update" event?

Much thanks!!
 
djh,

Yes, that code should work, but you may experience some difficulties if you are using Link Master and Link Child properties of the subforms and if those properties will need to be changed when you set the source objects.

If you are using a combo box to determine which subform to use, then put that code in the After Update of that combo box.

You can set the focus on tab pages by this code:

Me.MyTabControl.Pages("PageName").SetFocus


[This message has been edited by DML (edited 07-19-2000).]
 
Thanks DML -

just need to clarify though.

So I type in

Code:
Me.MyTabControl.Pages("PageName").SetFocus

where? And this is for the tab controls right (which methinks is much better than subform visibility thing)?

Is "PageName" the name of the subform on a particular tab??

Sorry, I'm kinda new to this...
 
No Problem about being new...that's what this site is for right!?

The timing on changing the tabs depends on when you wanted to change the source object for the subforms. If you are still doing it based on a choice from a list or combo box, then the after update event of the list box or combo box would probably be your best bet. That way, the subform is "refreshed" as soon as the user makes a selection.

Hint: If you rely on the Click event of a button, it may lead to some confusion if the users gets up and walks away, then comes back and forgets that they didn't click the button (the subform may not match the selection in this case)

You can actually reference a tab by its name or its index. The way I showed you above is how you reference a Page by what is in its name property. (Click inside the tab control, on one of the tabs to find the Page properties) If you want to reference a tab by its index (ordinal from leftmost tab to rightmost tab) then this is the syntax:

me.MytabControl.pages(1).SetFocus -- It is important to remember that it is zero based, meaning that 0 = first tab, 1 = second tab, 2 = 3rd tab, etc.
 
Ok, so I'm still missing one thing. I can set the code on the combo box (which I've decided to use) to get a subform of a tab on top. I assume it would work the same if I wanted to disable and enable it, right?

But the part I'm not quite getting is that of the tab objects. Don't I need to set something where intially they are disabled or greyed out or something, until the combo box choice allows the opposite? I think that makes sense...

Thanks for your help DML...
 
You can set the enabled or locked property for the subform control that is on the page of the tab. You can also set the style property for the tab control to None. This will hide the Tab part of the tab, so that it will be transparent to the user that you are using a tab control (then they can't change the tabs on you!)

Also, you can change the page index for the pages so that there is a default tab showing (the page with a page index of 0 (zero) will be the one to show when the form is opened.

You are correct, you refer to the locked and enabled properties of the subform CONTROL the same way that you would refer to the text box properties (Notice you are referring to the Control name, not the subform name -- there is a difference!!!).

me!SubformControlName.locked = true


[This message has been edited by DML (edited 07-19-2000).]
 
You might also like to try playing with the Visible Property of the pages in the Tab control (i.e. set all the pages to Visible = false, then set the selected one to True each time)

That way, the user only sees the tab relevant to the selection in the combo box but when the form is opened in design view, it's easy to get at all of your subforms.

While we're on this topic; I take it that the nature of the data that you're displaying in the magic subforms is very different (i.e. different columns) for each one and this is why you can't just requery the subform datasheet based on the value of the combo box??

Mike
 

Users who are viewing this thread

Back
Top Bottom