如何在Microsoft Access的表达式中引用当前表单? [英] How do I reference the current form in an expression in Microsoft Access?
问题描述
我不是Access专家,我有一个(我希望!)简单的问题...
I'm no Access expert, and I have an (I hope!) simple question...
我有一个带有许多记录的表格.在某些文本框中,我只是显示基础表中的值-因此它们被绑定到相应的字段.
I have a form with a number of records. In some textboxes I just present values from the underlying table - so they are bound to the corresponding fields.
但是某些文本框应包含计算值.一些计算很复杂,涉及表中的许多字段.我将计算结果写为VBA函数.我可以在控制源"中输入如下内容:
But some textboxes should contain calculated values. Some calculations are complicated and involves many fields from the table. I write the calculation as a VBA function. I could enter something like this as "Control Source":
=MyFunction([Field1], [Field2], [Field3] ...)
但是我不想在函数调用中列出数十个字段.相反,我想将整个表单(或当前记录)作为参数发送,并让函数引用所需的字段.我可以这样:
But I don't want to list dozens of fields in the function call. Instead, I want to send the whole form (or the current record) as a parameter, and let the function reference the fields it needs. I can do it like this:
=MyFunction([Forms]![MyForm])
但是我不喜欢必须在通话中命名表单.没有办法将当前形式"作为函数参数发送吗?在VBA中,只需使用"Me"关键字,例如"Me![Field1]".但似乎表达式中不接受我".
But I don't like having to name the form in the call. Isn't there a way to send the "current form" as a function argument? In VBA, you just use the "Me" keyword, for exampel "Me![Field1]". But it seems like "Me" isn't accepted in an expression.
还有其他方法可以在表达式中引用当前表格吗?
Is there some other way to reference the current form in an expression?
(我知道这是一个修饰性的问题.但是使用"[Form]![MyForm]"并不是一个好的编程.后来,您将控件复制到另一种表单中,而忘记了更改表达式中的名称... )
(It's a cosmetic question, I know. But it's not good programming to use "[Form]![MyForm]". Later on you copy the controls to another form and forget to change the name in the expression...)
感谢您的帮助! :-)
Grateful for your help! :-)
/安德斯
推荐答案
您可以使用:
=MyFunction([Form])
代码为:
Function MyFunction(frm As Form)
MsgBox frm.Name
End Function
这篇关于如何在Microsoft Access的表达式中引用当前表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!