vba Access 2010:从子表单中选择的记录值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21735704/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 17:45:49  来源:igfitidea点击:

Access 2010: Selected record value from subform

formsvbams-access-2010subform

提问by user3302702

Thank you in advance for the help for this problem - it has been driving me mad.

预先感谢您对这个问题的帮助 - 它一直让我发疯。

First of all: My question is regarding the how-to here: http://www.fmsinc.com/MicrosoftAccess/Forms/Synchronize/LinkedSubforms.asp.

首先:我的问题是关于这里的操作方法:http: //www.fmsinc.com/MicrosoftAccess/Forms/Synchronize/LinkedSubforms.asp

I have a form in Access 2010 that contains a subform. The content of the subform is updated with VBA. Everything works great here.

我在 Access 2010 中有一个包含子表单的表单。子窗体的内容用 VBA 更新。这里一切都很好。

I want to be able to open another form based on the record, that the user has chosen in the subform. This entails knowing the number of the record selected by the user. To start with, I just what the ID of the chosen record to be written into a normal textbox in the form.

我希望能够根据用户在子表单中选择的记录打开另一个表单。这需要知道用户选择的记录编号。首先,我只是将所选记录的 ID 写入表单中的普通文本框。

I found the solution in the above-metioned link. It says:

我在上面提到的链接中找到了解决方案。它说:

"To reference a value in a subform, use the following syntax for the text box's Control Source property:

=[subFormName].[Form]![ControlName]"

“要引用子窗体中的值,请对文本框的控件源属性使用以下语法:

=[subFormName].[Form]![ControlName]"

It works perfectly in their example (I have downloaded the .mdb and it works!), but when I try, the "[Form]" is not an option. And so, I cannot get it to work!

它在他们的示例中完美运行(我已经下载了 .mdb 并且它可以工作!),但是当我尝试时,“[Form]”不是一个选项。所以,我无法让它工作!

I tried in their .mdb as well, and I cannot chose [Form] either, so as soon as I change the control source property of the textbox, it stops working. I have tried with [.Formula] instead, but nothing (link to screenshot: http://i.imgur.com/pR2WkSW.png?1)

我也在他们的 .mdb 中尝试过,但我也不能选择 [Form],所以只要我更改了文本框的控件源属性,它就会停止工作。我已经尝试过 [.Formula],但没有(链接到屏幕截图:http: //i.imgur.com/pR2WkSW.png?1

What could be the problem? Maybe language settings?

可能是什么问题呢?也许语言设置?

Thank you so much in advance.

非常感谢你。

M.

M。

回答by parakmiakos

I'm not sure how it's different in Access 2010 but as you can see below, for Access 2007 :

我不确定它在 Access 2010 中有什么不同,但正如您在下面看到的,对于 Access 2007:

referencing a subform control

引用子表单控件

You can directly refer to a control in the Expression Builder. Just :

您可以直接引用表达式生成器中的控件。只是 :

a) expand your form name on the left frame

a) 在左侧框架中展开您的表单名称

b) select your subform name on the left frame

b) 在左侧框架中选择您的子表单名称

c1) If you want to refer to a specific control (i.e. a text box) simply select it from the middle frame (double click on it)

c1) 如果要引用特定控件(即文本框),只需从中间框架中选择它(双击它)

c2) If you want to refer to a form property (i.e. the subform's filter) select the tag in the middle frame, and the corresponding property in the right frame

c2) 如果要引用一个表单属性(即子表单的过滤器)在中间框选择标签,在右边框选择对应的属性

c3) If you want to refer to an item of the subform's recordset, use the tag in the middle frame and select the item from the right frame

c3) 如果要引用子表单记录集中的某个项目,请使用中间框架中的标记并从右侧框架中选择该项目

It should all be there.

它应该都在那里。

回答by Robert Yarbrough

You should be able to reference the control through VBA in a slightly different manner. The forms show up as classes with Form_in front of them (which is nice because you get to use intellisense). So your syntax would be similar to the following:

您应该能够以稍微不同的方式通过 VBA 引用控件。表单显示为Form_它们前面的类(这很好,因为您可以使用智能感知)。因此,您的语法将类似于以下内容:

Form_Formname.Controls("ControlName").Value 

That should get you the value of the control on the selected record. I realise this is pretty old, but I was looking for the answer to this very question, and was able to figure it out on my own with a little experimentation.

这应该可以让您获得所选记录上控件的值。我意识到这已经很老了,但我一直在寻找这个问题的答案,并且能够通过一些实验自行解决。