PDA

View Full Version : Here i go again...How to open/close different subforms from the main form?



mud2
03-14-2006, 05:36 PM
How do I open or close different "subforms" from the main form?

matthewspatrick
03-14-2006, 07:21 PM
Can you describe what you mean a bit more fully :think:

mud2
03-14-2006, 08:14 PM
What happened? I had a page full of clarifications!! Oh well, here goes again!

I have several forms, based on tables and queries. I want a Main form to contain buttons for each of these forms so when clicked the form will open as a subform. I can do this simply by opening the subform as a form on top of the main form, but that's too messy!

wadiohead
03-15-2006, 08:40 AM
Should be fairly simple.

Create a subform on the main form; leave it's SourceObject, Link Child Fields, and Link Parent Fields properties blank if you don't want it to open immediately to a default subform; otherwise, fill them into your "default" value.

The subform is contained in a "child object" whose name you'll be able to see in the properties (you might want to rename it from Child1 or whatever to something more meaningful). The child object can be manipulated to contain whatever subform you'd like.

So on the On_click event of your button, you can change the subform of the child and its linked fields by using something like this:

Private Sub Command2_Click()
Me.ChildName.SourceObject = "frmSub1"
Me.Child0.LinkMasterFields = "Field1;Field2"
Me.ChildName.LinkChildFields = "Field1;Field2"

End Sub

An alternative approach would be to use a tab control, which you can find out more about here:

http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/office97/html/usingtabcontroltoorganizeforms.asp

Hope this helps.

-David

GaryB
03-15-2006, 03:33 PM
Would this work?

I have a similar situation and did it with macro's. When I click the button it opens the form assigned to that button and closes the main form. Then on exit from the subform I created a button with a macro to reopen the mainform and close the subform. Keeps it clean and simple but everything goes back to the main form.

Gary