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

Opening/Closing Subform with command buttons 1

Status
Not open for further replies.

tdezwaan

Technical User
Jun 29, 2001
5
US
I have two command buttons that I am using to open and close a subform. To open the subform in the main form I am using the code:

Private Sub OpenSubform_Click()

Me![SubformName].Form.Visible = True

End Sub

To close the subform in the main form I am using the code:

Private Sub CloseSubform_Click()

Me![SubformName].Form.Visible = False

End Sub

The command buttons work as I want them to, the problem is that when I open the main form I get a message box saying "Microsoft Access can't find the form 'SubformName' referred to in a macro expression or Visual Basic code." If I click "OK" to get out of this message box, the main form opens and the command buttons work as expected. Does anyone know why the message box is popping up and what I can do to eliminate it?

Thank you!
 
You're getting that error message because Access needs to set references to the controls on the subform, and cannot do this while the subform is not visible. You would need to set the subform's visible property to Yes in Design view, and then set it's visible property to No in the main Form's On Activate event (or possibly the On Got Focus event)

HTH
Lightning
 
Thanks very much! Setting the visible property to no in the main form's On Activate or On Load worked. When I set the visible property to no in On Got Focus, the subform was visible when I opened the main form though (?).

tdezwaan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top