对子窗体的Form属性的无效引用(ms Access 2007) [英] Invalid reference to Form property of subform (ms Access 2007)
问题描述
I'm using a technique similar to that in Remou's answer to this question to manipulate the propeties of the controls on a subform. Works great as long as the parent form's recordset has at least one record. If the parent form has no records, I get:
错误2455,您输入的表达式对属性Form/Report的引用无效."
Error 2455, "You entered an expression that has an invalid reference to the property Form/Report."
当我尝试递归调用时抛出错误.下面是该代码的简化版本(我删除了错误处理及其他一些案例,包括其他案例).该代码位于一个模块中,并从我的应用程序中大多数表单的Load事件中调用:
The error is thrown when I attempt the recursive call. A simplified version of the code is below (I've stripped out error handling & a couple more Cases, including an Else). This code lives in a Module and is called from the Load event of most forms in my application:
Public Sub LockUnlockForm(frmLoad As Form)
Dim ctl As Control
For Each ctl In frmLoad.Controls
With ctl
Select Case .ControlType
Case acTextBox, acComboBox, acCheckBox
.Locked = Not gblnAuthorized
Case acSubform
LockUnlockForm .Form '<--- this line errors
End Select
End With
Next
End Sub
我现在要在给我带来问题的表单上要做的是在父级上创建一个新记录,并允许用户向子表单添加数据(如果gblnAuthorized
为True,或者设置一个简单的消息(如果为False).我别无选择,只能在致电LockUnlockForm
之前这样做吗?创建新的父级表单记录甚至可以防止此错误吗?
What I want to do on the form that's giving me the problem right now is to create a new record at the parent level and allow the user to add data to the subform (if gblnAuthorized
is True, or set a simple message if it's False). Do I have no choice but to do that before calling LockUnlockForm
? Will creating a new parent-form-level record even work to prevent this error?
推荐答案
确定记录的数量 表单的记录集,并且仅运行For 每个循环,当记录计数> 0时.
Determine the record count for the form's recordset and only run the For Each loop when the record count > 0.
我正在回答这个问题,以便其他有相同问题的用户可以轻松确定所提供的答案.它已经过了一个月的陈旧.如果可以的话,将信用转给HansUp!
I'm answering this so other users with the same problem can easily determine the answer that was provided. And it's gone a month stale. Pass the credit to HansUp if you can!
这篇关于对子窗体的Form属性的无效引用(ms Access 2007)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!