简体   繁体   English

对子窗体的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. 我使用的技术类似于Remou对这个问题的回答,以操纵子窗体上控件的性能。 Works great as long as the parent form's recordset has at least one record . 只要父窗体的记录集至少有一条记录,就可以正常工作 If the parent form has no records, I get: 如果父表单没有记录,我得到:

Error 2455, "You entered an expression that has an invalid reference to the property Form/Report." 错误2455,“您输入的表达式对属性表单/报表具有无效引用。”

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: 此代码位于Module中,并从我的应用程序中的大多数表单的Load事件中调用:

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

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). 我想在现在给我问题的表单上做的是在父级创建一个新记录,并允许用户将数据添加到子表单(如果gblnAuthorized为True,或者设置一个简单的消息,如果它是False) 。 Do I have no choice but to do that before calling LockUnlockForm ? 在调用LockUnlockForm之前,我LockUnlockForm吗? Will creating a new parent-form-level record even work to prevent this error? 创建新的父表单级记录是否可以防止此错误?

Determine the record count for the form's recordset and only run the For Each loop when the record count > 0. 确定表单记录集的记录计数,并且仅在记录计数> 0时运行For Each循环。

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! 如果可以,将信用证转给HansUp!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM