Invalid reference to Form property of subform (ms Access 2007)

送分小仙女□ 提交于 2020-01-14 14:25:28

问题


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:

Error 2455, "You entered an expression that has an invalid reference to the property Form/Report."

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

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?


回答1:


Determine the record count for the form's recordset and only run the For Each loop when the record count > 0.

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!



来源:https://stackoverflow.com/questions/5023631/invalid-reference-to-form-property-of-subform-ms-access-2007

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!