文章标题:Referring to Controls on a Subform
来源:http://allenbrowne.com/casu-04.html
Sooner or later, you will need to refer to information in a control on another form - a subform, the parent form, or some other form altogether. Say for example we have a form called "Students" that displays student names and addresses. In this form is a subform called "Grades" that displays the classes passed and credit points earned for the student in the main form. How can the Students form refer to the Credits control in the Grades subform?
Access refers to open forms as "Forms". Using the dot as a separator, the Surname control on the Students form can be referenced as: Forms.Students.Surname
If there are spaces in the names of your objects, use square brackets around the names, e.g.: Forms.[Students Form].[First Name]
Now, the area on a form that contains a subform is actually a control to just have a look at it in design view. This control has a ".form" property which refers to the form that it holds. This ".form" must be included if you wish to refer to controls in the subform. For example: Forms.Students.Grades.Form.Credits
where "Students" is the name of the parent form, "Grades" is the name of the control that holds the subform, and "Credits" is a control on the subform.
Once you get the hang of referring to things this way, you will use it incessantly, to SetValue in macros, to print a report limited to a certain financial period (the WHERE clause in the OpenReport action) etc.
Check the Access Help for the shortcuts offered by the Me and Parent references.
译文:谈谈子窗体中的控件
迟早你要了解一些有关窗体,子窗体的控件,总之包括主窗体及其他的一些窗体中的。我们举个例子来说:有一个窗体叫做“学生”,需要显示学生姓名和地址,在这个窗体中有个子窗体叫做“年级”它通过班级建立点获得与学生主窗体的联系。怎样从学生窗体中建立控件来打开“子窗体”呢?
ACCESS可以引用窗体打开窗体,使用句点分离,这样子窗体的姓名就能够被主窗体引用了:
Forms.Students.Surname
如果这里是对象,那么用方括号在姓名周围把它们括在一起等等。
Forms.[Students Form].[First Name]
现在,这个区域的窗体里也包含了一个激活的子窗体控件。这只是仅仅能够在设计模式中看到。窗体有一个特性就是那里需要引用或是保存。这个窗体必须包含你所引用控件的子窗体中 。例如:
Forms.Students.Grades.Form.Credits
“学生”这个名字来自主窗体,子窗体中“年级”的名字由控件控制,以及子窗体中的信任关系。
一旦你能够用这种悬挂式的方式调用,要赋值给宏,要打印受限制的某个时期的报表等等,你将会不间断的使用它。
查看当前窗体的及子窗体中的帮助也是一种学习的捷径。
翻译:飞天业
[此贴子已经被作者于2005-8-23 18:27:41编辑过]
|