code to open a subform (1 Viewer)

Nic

Registered User.
Local time
Today, 10:17
Joined
Jan 15, 2012
Messages
47
Hi,
Iv got a form with a 'subform' on it.
I have a cmd button, that when clicked i would like my 'suppliers' form to appear in the subform.
Any suggestions on the code i need to put in the onclick event of my cmd button?

Many thanks,
 

bob fitz

AWF VIP
Local time
Today, 10:17
Joined
May 23, 2011
Messages
4,726
Any control on a form (including a subform) can be made visible or hidden by setting its "Visible" property to True or False. In code this would be done with:

Me.ControlName.Visible = True
or
Me.ControlName.Visible = False

Replace ControlName with the name of the control not the name of the actual subform which may or may not be the same.
 

Nic

Registered User.
Local time
Today, 10:17
Joined
Jan 15, 2012
Messages
47
Hi,
Thanks for reply,
Im thinking of a slightly different approach though.
I am hoping to use the 'subform' on my form to display different forms dependent on which cmd button in selected by the user.

I am thinking of come code that would set the source object of my subform(???) something such as:

Me.SubForm.SourceObject = Forms.Suppliers

The above code doesnt work, but it might help explain what i am trying to do.
Many thanks,
 

bob fitz

AWF VIP
Local time
Today, 10:17
Joined
May 23, 2011
Messages
4,726
Why not put a Tab control on the form. Then create a tab for each subform that you want and put a subform on each tab.
 

Bryan

Registered User.
Local time
Today, 05:17
Joined
May 7, 2012
Messages
124
Do you have a number of subforms that only one or none needs to be visible at one time? If that's the case, you can add a number of subforms to your main form and overlap them. Set them all to invisible. On your main form, code command buttons, one for each subform, to make the appropriate one visible and the rest invisible.

See THIS THREAD for more detail.
 

bob fitz

AWF VIP
Local time
Today, 10:17
Joined
May 23, 2011
Messages
4,726
Do you have a number of subforms that only one or none needs to be visible at one time? If that's the case, you can add a number of subforms to your main form and overlap them. Set them all to invisible. On your main form, code command buttons, one for each subform, to make the appropriate one visible and the rest invisible.

See THIS THREAD for more detail.
IMHO Using a single tab control would be easier than using several buttons.
 

Simon_MT

Registered User.
Local time
Today, 10:17
Joined
Feb 26, 2007
Messages
2,177
Whether or not you use a tab or subform this is what I do. I have a flag to track that the subform has been loaded.

Code:
Function ArtistsEntry_PageNo()

'       This function is designed to speed up the Artists Forms, by making the Originals History and Consignments On Demand only

    With CodeContextObject
        .[Page No] = .[TabCtl0]

        If .[ACFlag] <> True And .[Page No] = 3 Then
            .[ACFlag] = True
            .[Artists Consignments].SourceObject = "Artists Consignments"
        End If
        If .[OHFlag] <> True And .[Page No] = 4 Then
            .[OHFlag] = True
            .[Artists Originals History].SourceObject = "Artists Entry Originals History"
        End If
    End With

End Function
Simon
 

Nic

Registered User.
Local time
Today, 10:17
Joined
Jan 15, 2012
Messages
47
Hi,
Used a tab form and it does exactly what i need.
Thanks for all the suggestions!
 

Users who are viewing this thread

Top Bottom