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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

control subform visibility via command button

Status
Not open for further replies.

Dbyte

Technical User
Mar 6, 2002
87
0
0
Main form is called frmNewTicket, subform is called fsubClose. fsubClose's default visible property is No. I created a command button on frmNewTicket & for its OnClick event I have the following code:
Code:
Private Sub Command87_Click()
    Me!Forms!fsubClose!Form!Visible = True
End Sub
When I click on the command button I get the following error: "Run-time error '2465': Microsoft Office Access can't find the field 'Forms' referred to in your expression."
I have also tried:
Code:
Me!fsubClose!Form!Visible = True
Which gives me essentially the same error.
The subform is on the main form & I know it's loaded because when I step thru the expression builder both frmNewTicket & fsubClose are listed under Loaded Forms.

I don't want to use a Tab control due to its layout restrictions.
 
Found the solution:
1. Created an OnOpen event on fsubClose that invoked the code builder. No specific code added, but now it showed in the lefthand pane of the Visual Basic coding popup.
2. Changed my OnClick event on frmNewTicket as follows:
Code:
Private Sub Command87_Click()
    If Form_fsubClose.Visible = True Then
        Form_fsubClose.Visible = False
    Else
        Form_fsubClose.Visible = True
    End If
End Sub

Lessons learned:
1. Make sure any/all objects referenced by code builder are visible in VB window.
2. Bangs (!) are for fields, periods (.) are for objects.
3. The If/Then statement allows me to toggle the visibility, which will give the end users more flexibility.

Can I give myself a star? [wink]
 
Replace this:
Me!Forms!fsubClose!Form!Visible = True
with this:
Me!fsubClose.Form.Visible = True

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top