Opening subform within navigations (ELI5)

2019-09-03 16:31发布

I have an access database I'm building (i've posted occasionally with my questions) and I have a general question about ms access:

How do you open a subform within a navigation form?

I have a master/child tree that is:

Main Navigation Form -> Main Student Records Navigation Form -> View All Students Datasheet -> View Edit Student

My goal is to click on the ID of a record in the datasheet, and have it open the "view/edit student" that displays the full details (the datasheet only has a few elements to it).

But I honestly don't understand how to call a subform to open like that. I've read about it, and I thought it'd be something like

DoCmd.OpenForm Forms!NavigationForm.StudentNav_Form.ViewEditStud_Form

But this doesn't work. But this problem I'm having I feel like is systemic to the way access works. I'm not sure I understand how referencing and calling objects within VBA works. Reading the msdn articles is only confusing me more >.<

Thanks all!


EDIT: I found this: navigating to a different tab in navigation subform

The BrowseTo command seems like what I want, but I'm not sure I understand how to write the syntax to move to the right page... I'm going to experiment but if anyone has any idea I'd love to know!

2条回答
祖国的老花朵
2楼-- · 2019-09-03 16:45

I've solved it. I didn't want DoCmd.Open I wanted DoCmd.Browseto as described in the post above. The syntax for the browse to looks like:

DoCmd.BrowseTo acBrowseToForm, "ViewEditStud_Form", "NavigationForm.NavigationSubform>StudentNav_Form.NavigationSubform"

It took me a while to understand this so I'm going to break it down.

acBrowseToForm tells it that I'm browsing to a form (obviously!) "ViewEditStud_Form" is the form that I'm browsing to. "NavigationForm.NavigationSubform>StudentNav_Form.NavigationSubform" is the instructions of where to open it. NavigationForm is the name of my main navigation form. .NavigationSubform> identifies that there is a subform to open it in, and that subform is StudentNav_Form which holds a navigation subform (and the end of that indicates that that subform is where the form is to be opened in!)

Hope this helps anyone else!

查看更多
欢心
3楼-- · 2019-09-03 17:00

Honestly, form navigation was one of the hardest things for me to get used to when I started programming in access. I think what you are looking for is something like this:

DoCmd.OpenForm "FormName", acNormal, "", "[Record_ID] = " & Me.Record_ID, , acNormal

If your Record_ID is for some reason a string it would be with single quotes like this:

DoCmd.OpenForm "FormName", acNormal, "", "[Record_ID] = '" & Me.Record_ID & "'", , acNormal

Obviously you will need to replace FormName with the name of the form you want to open, and Record_ID with the actual name of that column. By the looks of it your FormName is likely ViewEditStud_Form.

查看更多
登录 后发表回答