Close subform but leave main form open

J

JoeP

I have a main form in datasheet view called MainForm. On MainForm is a
subform called DataSubForm. DataSubForm has a Close command button on it.
When I open the subform and enter my data I want to be able to click the
Close button on the subform to close it (collapse it out of the way) and
leave MainForm open.

I placed the following coding on the command button...
DoCmd.Close acForm, "DataSubForm"

If I open DataSubForm by itself to test the command button it closes properly.
When the MainForm is open and I try to click the Close button on DataSubForm
nothing happens.

What step am I missing? Thanks for any help.

JoeP
 
L

Linq Adams via AccessMonster.com

Once DataSubForm is placed on the Main Form as a subform, it is, in essence,
no longer a form! It is now a control (a subform control) and part of the
Main Form, and has to be handled as such. What I'd do is place a button on
the Main Form and use it to control the visibility of the subform. Name it

SubOpenClose

Set it's Caption as

Close Subform

Private Sub SubOpenClose_Click()
If SubOpenClose.Caption = "Close Subform" Then
YourSubformName.Visible = False
SubOpenClose.Caption = "Open Subform"
Else
YourSubformName.Visible = True
SubOpenClose.Caption = "Close Subform"
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top