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

VBA to open a Navigation Form subform

Status
Not open for further replies.

jgm835

Programmer
Dec 29, 2012
4
US
I have several subforms in a Navigation Form in Access 2010. I know I can reference and retrieve the subform name currently open with Forms![Navigation Form]!NavigationSubform].[Form].Name, but it is a read only property. I want to programmatically switch or open one of the subforms from another one. I have seen quite a few similar posts, but none that I saw had answer that worked on my system. I have tried using the DoCmd.BrowseTo but apparently haven't formulated it correctly. Tell me what I'm missing. Thanks
 
if you want to open a form use the docmd.openform
If you want to change the subform on the current mainform you need to change the sourceobject of the subform control. Something like
me.subformcontrol.sourceobject = "formName"

I do not know what it means to open a subform from another.
 
Thanks for the reply. That probably works in subforms for regular forms but I haven't been able to get it to work in the new Navigation Form with Access 2010. I had tried that from code in both command buttons and the load and open events of the Navigation Form. It does not compile. The Error message on ".subformcontrol" is Compile error, Method or data member not found. If I use the DoCmd it will open as a separate form, but not as a subform of the Navigation Form. I haven't yet found a way to refer to it in the parameteres of either the DoCmd.OpenForm or the DoCmd.BrowseTo commands.

By open a subform from another I am referring to the situation where a subform is open in a Navigation Form and it is desired to switch to another subform of that same Navigation Form with code. I want to do in code what a simple click on the other subforms "tab" label does.
 
I finally answered my own question with the correct parameters in the DoCmd.BrowseTo command as follows:
DoCmd.BrowseTo ObjectType:=acBrowseToForm, _
ObjectName:="frmBatesFiles", _
PathToSubformControl:="Navigation Form.NavigationSubform", _
DataMode:=acFormEdit
The difficulty I was having was with the PathToSubformControl parameter. I had put square brackets around the form names containing spaces. When I removed the brackets it worked fine. I'm still open to other ways.
 
Sorry, I did not see you are using a navigation form. The browseto method is correct. So can you show the name of your main form and subforms adn how you tried to formulate it?
 
You asked about the name of my main form and subform. I actually did use them. I simply kept the Default Name of "Navigation Form" and "NavigationSubform" for the container. It helped to keep things simple until I'm more familiar with the Navigation Form. The odd thing about it was that even though spaces were present in the form names, it didn't work with square brackets, as is necessary in using the Forms!MainFormm, etc terminology. It's like Microsoft didn't follow their own recommendations. If you know of other ways of addressing Navigation Forms I'd be interested. Thanks for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top