Solved Close a subform without closing the parent Form (1 Viewer)

yamus

Member
Local time
Today, 02:01
Joined
Aug 12, 2020
Messages
81
Hello
I have 2 forms: frmA and frmB.
frmB is a subForm of frmB
frmB has a close button. I used the DoCmd.close command attempting to close frmB but what happens is that frmA also closes.
What can I do to prevent frmA from closing? In other words, I want to close only frmB
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 18:01
Joined
Oct 29, 2018
Messages
21,473
Can you show us your code?
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 21:01
Joined
May 21, 2018
Messages
8,528
If it is a subform you can set the subform control to Visible = false. Or you can set the source object to ""
 

yamus

Member
Local time
Today, 02:01
Joined
Aug 12, 2020
Messages
81
Hello
I have 2 forms: frmA and frmB.
frmB is a subForm of frmB
frmB has a close button. I used the DoCmd.close command attempting to close frmB but what happens is that frmA also closes.
What can I do to prevent frmA from closing? In other words, I want to close only frmB
Hi
I attached to images
1- The parent formA within which is frmB
2- The code in the "close button" event
As you can see, I only used DoCmd.close command
 

Attachments

  • img_1.PNG
    img_1.PNG
    26.4 KB · Views: 219
  • img_2.PNG
    img_2.PNG
    2 KB · Views: 203

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 21:01
Joined
May 21, 2018
Messages
8,528
You should never use close without explicitly stating what to close. You can get inadvertent results. The code should always be
docmd.close ACFORM, Me.name
This ensures you are closing the thing you want.
 

Isaac

Lifelong Learner
Local time
Yesterday, 18:01
Joined
Mar 14, 2017
Messages
8,777
Why would you want to close a subform without closing the main form? The subform is embedded in the other form.
That's like saying I want to cut down this tree--but only the "middle" of it, I'd like the rest of the trunk on bottom and top to keep standing.
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 21:01
Joined
May 21, 2018
Messages
8,528
AFAIK, there is no way to "close" as form instantiated as a subform. If you want to make it look like it closes see my original response and two examples. Wiping out the sourceobject will leave the subform control still visible. Or you can hide it.
 

Attachments

  • CloseSub.accdb
    1.3 MB · Views: 217

yamus

Member
Local time
Today, 02:01
Joined
Aug 12, 2020
Messages
81
AFAIK, there is no way to "close" as form instantiated as a subform. If you want to make it look like it closes see my original response and two examples. Wiping out the sourceobject will leave the subform control still visible. Or you can hide it.
Hi
It is exactly as you mentionned. After few searches online, I came across the idea of hiding subforms as if they are being closed.
I disabled the focus on the subform by setting the focus on another contol from the parent form and then I set the visibilty of the subform to none
Thank you anywaty for the help
 

yamus

Member
Local time
Today, 02:01
Joined
Aug 12, 2020
Messages
81
Hi
Thank you everybody. I think I found a solution.
1- Disable the focus on the subform by setting focus on another control from the parent form
2- Set the visibility of the subform to false
Once again, I appreciate your help
 

Users who are viewing this thread

Top Bottom