更改子报表记录源时出错:“您输入的表达式对属性Form / Report的引用无效”

时间:2018-07-23 14:57:22

标签: vba ms-access access-vba

我有一个带有子报表的表格,偶尔会引用/更改该报表的记录源。 几个月,它一直运行良好。我最近回过头来,开始调整其中的一些内容,即制表符顺序。我添加了一些代码,用于检查用于打开该按钮的按钮,并根据该按钮更改选项卡顺序。一旦我开始测试它是否有效,错误

  

”您输入的表达式对   财产表格/报告”

开始出现在引用报表记录源的每一行上。我试着删除错误出现之前添加的代码,但这并没有导致错误消失。

出现错误的代码示例:

Me.rRAM10x10.Report.RecordSource = "tRAM10x10"

我在错误开始之前添加的代码:

If CurrentProject.AllForms("fHighRisk").IsLoaded = True Then
    If Screen.ActiveControl.Name = "btnRAMimpact" Then
        Me.btnForFocus.TabIndex = 0
    ElseIf Screen.ActiveControl.Name = "btnRAMlhood" Then
        Me.Tabordertest.TabIndex = 0
    End If
End If

我进行了一些研究,发现这可能是由父表单没有任何记录引起的,但事实并非如此。除了我在上面发布的内容之外,自从我在几个月之前完成对其进行更改以来,尚未对此表格,报告或我将其记录源设置为的任何表格进行任何更改。

表单的OnOpen事件:

Private Sub Form_Open(Cancel As Integer)
Dim sID As Integer

If CurrentProject.AllForms("fRiskAssessmentTest").IsLoaded = True Then
    sID = Forms!fRiskAssessmentTest!fHighRisk!ScenarioID.Value
ElseIf CurrentProject.AllForms("fHighRisk").IsLoaded = True Then
    sID = Forms!fHighRisk!ScenarioID.Value
Else
    sID = 1
End If

Me.lblScenarioID.Caption = "Scenario " & sID

If CurrentProject.AllForms("fHighRisk").IsLoaded = True Then
    If Screen.ActiveControl.Name = "btnRAMimpact" Then
        Me.btnForFocus.TabIndex = 0
    ElseIf Screen.ActiveControl.Name = "btnRAMlhood" Then
        Me.Tabordertest.TabIndex = 0
    End If
End If

clr1 = RGB(122, 197, 205)
clr2 = RGB(152, 245, 255)

'button colors
Dim lblName As String, btnName As String, lblCaption As String, Rating As                 
Integer, ctrl As Control

For Each ctrl In Me.Controls
    If ctrl.ControlType = acCommandButton Then
        ctrlName = ctrl.Name
        Me.Controls(ctrlName).BackColor = clr2
    End If
Next

'Darkens buttons if value is stored in table
For i = 1 To 5
    lblName = "Vardisp" & i
    lblCaption = Me.Controls(lblName).Caption
    If IsNull(DLookup("[Variable Impact]", "tImpact", "scenarioID = " & sID &     
" AND [Impact Variable] = """ & lblCaption & """ ")) Then
        GoTo Skip_loop2
    Else
        Rating = DLookup("[Variable Impact]", "tImpact", "scenarioID = " & 
sID & " AND [Impact Variable] = """ & lblCaption & """ ")
    End If

    For b = 1 To 10
        If Rating = b Then
            btnName = "Var" & i & "R" & b
            Me.Controls(btnName).BackColor = clr1
        End If
    Next

Skip_loop2:
Next

End Sub

我对造成这种情况的原因感到迷茫,因此非常感谢您的帮助。我能够找到的与之相关的一切都是由父表单记录集没有任何记录引起的,由于这里不是这种情况,因此,我正在努力寻找前进的方向。

谢谢!

0 个答案:

没有答案