Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pass subform name to parent form function 1

Status
Not open for further replies.

Jean9

Programmer
Dec 6, 2004
128
US
I have several subforms on a main form that are set to invisible. Depending on what button a user clicks, I want to make visible a single subform and set the others to invisible. I would like to just pass the subform name to a function that makes all subforms invisible and just the subform passed visible with a single line of code or very few lines (In short, avoid using a select case on a passed function parameter). I don't know how to pass the subform name and then what code should be used to set it to visible. I tried passing the subform as a form but got a message that the form couldn't be found. Everything I look at points to a subform on a main form being a control so my code looks like
[code/]
Private Sub FrmShow(cFORM As Control)

Me.NF_CTL.SetFocus
Me.SFADMIN_CATEGORY.Visible = False
Me.SFADMIN_CONTAINMENT.Visible = False
Me.SFADMIN_DEPT.Visible = False
Me.SFADMIN_DEPT_ACTIONS.Visible = False
Me.SFADMIN_OPER_DEPT.Visible = False
Me.SFADMIN_PAINTCODES.Visible = False
Me.SFADMIN_PASSWORDS.Visible = False
Me.SFADMIN_PERSONNEL.Visible = False
Me.SFADMIN_PRIORITY.Visible = False
Me.SFADMIN_DRWG_FMT.Visible = False
Me.SFADMIN_STATUS.Visible = False

cFORM.Visible = True
[/code]

But when I call the function using
FrmShow (SFADMIN_OPER_DEPT), I get a type mismatch error.

How can this best be accomplished?
Thanks in advance,
J9
 
How about:

Code:
Private Sub FrmShow(cFORM As String)

    Me.NF_CTL.SetFocus

For Each ctl In Me.Controls
    If ctl.ControlType=acSubForm Then
        If ctl.Name=cForm Then
            ctl.Visible=True
        Else
            ctl.Visible=False
        End If
    End If
Next

You can also refer to
Me(cForm).Property
Or
Me("SFADMIN_PASSWORDS").Properties

As an aside, I generally prefer to have just the one subform control and load various forms into it as required.

 
You're my hero for the day!! Thanks! That worked very nicely. Now maybe you can tell me about how to have just the single subform control and how to load that dynamically. I bet it's easy and would make a thousand times more sense than my gazillion subforms on one form.
 
You can add a tag to your command button(s) with the subform name, or use a combobox with a visible friendly name and a hidden real name - there are other possibilities, but these two should keep you going for now.

Code:
Me("sfrmAll").SourceObject = Me.cmdForm1.Tag

Code:
Me("sfrmAll").SourceObject = Me.cboForms

Shout if that is unclear. :)


 
Have a look at the SoourceObject property.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Sorry for the typo, I meant the SourceObject property.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
This way was even better. Thanks for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top