Avatar of ANTHONY CHRISTI
ANTHONY CHRISTIFlag for United States of America

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
Microsoft AccessVBA

Avatar of undefined
Last Comment
PatHartman
Avatar of Fabrice Lambert
Fabrice Lambert
Flag of France image

Hi,

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):
subForm.sourceObject = vbNullString

Open in new window

Avatar of Dale Fye
Dale Fye
Flag of United States of America image

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
Avatar of ANTHONY CHRISTI

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"]
Avatar of PatHartman
PatHartman
Flag of United States of America image

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
Avatar of ANTHONY CHRISTI

ASKER

ARDetail actually ON the  form on the navigation form.
Avatar of Dale Fye
Dale Fye
Flag of United States of America image

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.NavigationTargetName = ""
Lots of confusion here.
Can you upload your database ?
Avatar of PatHartman
PatHartman
Flag of United States of America image

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.
Avatar of ANTHONY CHRISTI

ASKER

ok, I figured it out, thanks for your help

DoCmd.Close acForm, "[Forms]![ARDetail]![NavigationSubform]", acSaveYes
Avatar of PatHartman
PatHartman
Flag of United States of America image

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.
Avatar of ANTHONY CHRISTI

ASKER

Thank you for that bit of information; but to prevent the record from being saved can I use undo?
ASKER CERTIFIED SOLUTION
Avatar of PatHartman
PatHartman
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of ANTHONY CHRISTI

ASKER

Pat, I do appreciate the information, Thanks
Avatar of ANTHONY CHRISTI

ASKER

I want to Thank all of you for your advice and comments.  I will be back.
Avatar of PatHartman
PatHartman
Flag of United States of America image

You're welcome.
Microsoft Access
Microsoft Access

Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.

226K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo