ANTHONY CHRISTI
asked on
MS Access closing a subforn form with a navigation form
I am trying to write vba code in MS Access 2016 to close a subform within a navigation form
Well, the Navigation form (I really hate these) has a subform control, usually named "NavigationSubform".
When you click on a tab in the Navigation form (design view) and display the properties (data tab), you will see the name of the form that is used as the SourceObject (although it is called the "Navigation Target Name".
I'm not sure if that helps
When you click on a tab in the Navigation form (design view) and display the properties (data tab), you will see the name of the form that is used as the SourceObject (although it is called the "Navigation Target Name".
I'm not sure if that helps
ASKER
Sorry, about my typos.
MS Access closing a subforn form with a navigation form s/b
========================== ========== ========== ========== ========== ========== ========== ==
I am looking for syntax to close a subform that is within a Navigation form.
The Navigation Form name is ARMain; the subform name is ARDetail
This will close the form if I open the subform by itself and it works ok.
DoCmd.Close acForm, Forms![ARMain]!["ARDetail" ]
MS Access closing a subforn form with a navigation form s/b
==========================
I am looking for syntax to close a subform that is within a Navigation form.
The Navigation Form name is ARMain; the subform name is ARDetail
This will close the form if I open the subform by itself and it works ok.
DoCmd.Close acForm, Forms![ARMain]!["ARDetail"
I guess I don't understand the point. Every time you click on a new tab, Access unloads the current subform and loads a new one. Do you really want to stay on this form and close the subform or are you just trying to be neat?
Is ARDetail actually ON the navigation form or is it on a form on the navigation form? If it is on a form that is on the form, you are missing a level of parentage in your close expression.
Otherwise, you are referencing the current form from "outside" and might have better success if you simply used
DoCmd.Close acForm, Me
Is ARDetail actually ON the navigation form or is it on a form on the navigation form? If it is on a form that is on the form, you are missing a level of parentage in your close expression.
Otherwise, you are referencing the current form from "outside" and might have better success if you simply used
DoCmd.Close acForm, Me
ASKER
ARDetail actually ON the form on the navigation form.
Do you want to keep the navigation form open?
Would you like to simply change the focus to another tab in the navigation form, or do you want to continue to display the tab and simply hide of close the subform?
The subform on the navigation form [ARDetail] will display the form associated with whichever tab is selected on the navigation form.
If you put a button in the navigation forms header, you might try something like:
me.ArDetail.NavigationTarg etName = ""
Would you like to simply change the focus to another tab in the navigation form, or do you want to continue to display the tab and simply hide of close the subform?
The subform on the navigation form [ARDetail] will display the form associated with whichever tab is selected on the navigation form.
If you put a button in the navigation forms header, you might try something like:
me.ArDetail.NavigationTarg
Lots of confusion here.
Can you upload your database ?
Can you upload your database ?
ARDetail actually ON the form on the navigation form.Then you are missing a level in the reference hierarchy.
When you use Forms! to reference a form/subform/control, you MUST include the COMPLETE hierarchy. When you use Me. You are running code inside some form/report that is refering to an object on THAT form/report or subform/subreport and so you only include the hierarchy from this form down (usually you would only be referencing one level down.
The navigation form is itself a form so any form you place on it becomes a subform. If that subform has a subform, then it is a subsubform. I think current versions of access support 5 levels (but check). Older versions only supported 3.
ASKER
ok, I figured it out, thanks for your help
DoCmd.Close acForm, "[Forms]![ARDetail]![Navig ationSubfo rm]", acSaveYes
DoCmd.Close acForm, "[Forms]![ARDetail]![Navig
You do realize that acSaveYes is referring to the form object and not the data, correct? Typically you would never want to save user changes to a form so it would be better to use the option that says save no prompt (look up the syntax). Access always automatically saves data when you close the form unless you write code to prevent it.
ASKER
Thank you for that bit of information; but to prevent the record from being saved can I use undo?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Pat, I do appreciate the information, Thanks
ASKER
I want to Thank all of you for your advice and comments. I will be back.
You're welcome.
Not sure to understand why you want to do that.
Well, just set the subform's sourceObject property to an empty string.
Sample code (according subForm is the name of the sub form control):
Open in new window