窗体选项卡控件子窗体运行时错误 468:对象不支持此属性或方法



我正在开发Access 2007中称为frmSearch的搜索表单/报表构建器。现有的搜索表单运行良好,在tabcontrol的子表单中显示其结果。然后我可以点击一个按钮来显示所有测试的报告,这很好。我想修改代码以显示单个fldTestsID的报告,但我坚持使用表单/子表单/控制路径语法。

有两个选项卡:tabResultsTabular将子表单frmResultsTabular显示为类似查询的行列表。tabResultsRecord显示子表单frmResultsRecords,显示一条记录。该报告是rpt_TestDatasetExposureEffects。报告的底层查询是q_TestDatasetExposureEffect,其中包含一个名为fldTestsID的字段。

路径是frmSearchtabResultsRecord,包含按钮cmdQAReportResultsfrmResultsRecordsfldTestsID

我看到其他帖子也有同样的错误,但没有让他们工作。DoCmd上的Access 2007文档。OpenReport没有提到这个具体的实例。

这是cmdQAReportResults点击事件的代码,包括我尝试过的选项。在strRptWhere =行失败。DoCmd.OpenReport语法是基于Access 2007文档的。

Private Sub cmdQAReportResults_Click()
    doQAReport
End Sub
Private Sub doQAReport()
'On Error GoTo Err_doQAReport 'comment during debugging
   Dim stDocName As String ' report name
'   Dim strRptSQL As String ' report SQL String
   Dim strRptWhere As String ' report WHERE clause
   stDocName = "rpt_TestDatasetExposureEffects"
    'Override the recordsource to match the current record TestsID
'   strRptSQL = "SELECT * FROM q_TestDatasetExposureEffects WHERE fldTestsID = " & fldTestsID
'   DoCmd.OpenReport stDocName, acPreview
    strRptWhere = "0 = 0"
    strRptWhere = "fldTestsID = " & Me.Form![tabResultsRecord].fldTestsID.Value 'error 468
'    other attempts follow
'    strRptWhere = "fldTestsID = " & Forms("frmSearch").Controls("tabResultsRecord").Form.Controls("frmResultsRecords").Form.Controls("fldTestsID").Value
'    strRptWhere = "fldTestsID = " & Me.Form.fldTestsID 'error 2465
   DoCmd.OpenReport stDocName, acPreview, , strRptWhere
'    Reports("rpt_TestDatasetExposureEffects").RecordSource = strRptSQL

Exit_doQAReport:
    Exit Sub
Err_doQAReport:
    MsgBox Err.Description
    Resume Exit_doQAReport
End Sub

正确的语法是:

Forms(<Parent Form>).<control container for subform>.form.<control>

在你的例子中,这可能是:

Forms("frmSearch").frmResultsRecords.Form.fldTestsID

frmResultsRecords是子表单的名称,但它也是子表单的容器的名称?

如果没有,则将其替换为包含子表单的主表单上的控件的名称。

最新更新