0

我正在 Access 2007 中开发一个名为frmSearch. 现有的搜索表单运行良好,在选项卡控件的子表单中显示其结果。然后我可以单击一个按钮来显示所有测试的报告,效果很好。我想修改代码以显示单个的报告fldTestsID,但我坚持使用 Form/Subform/Control 路径语法。

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

所以,路径是包含按钮frmSearch到to 。tabResultsRecordcmdQAReportResultsfrmResultsRecordsfldTestsID

我看到这是同样错误的其他帖子,但没有让它们工作。DoCmd.OpenReport 上的 Access 2007 文档未提及此特定实例。

这是cmdQAReportResults单击事件的代码,包括我尝试过的选项。失败就行了strRptWhere =。该DoCmd.OpenReport语法基于Access 2007 docs工作。

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
4

1 回答 1

1

正确的语法是:

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

在您的情况下,这可能是:

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

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

如果不是,请将其替换为包含子窗体的主窗体上的控件名称。

于 2013-06-18T07:28:51.410 回答