我正在 Access 2007 中开发一个名为frmSearch
. 现有的搜索表单运行良好,在选项卡控件的子表单中显示其结果。然后我可以单击一个按钮来显示所有测试的报告,效果很好。我想修改代码以显示单个的报告fldTestsID
,但我坚持使用 Form/Subform/Control 路径语法。
有两个选项卡:tabResultsTabular
将子表单显示frmResultsTabular
为类似查询的行列表。tabResultsRecord
显示一个子表单frmResultsRecords
,显示一条记录。报告是rpt_TestDatasetExposureEffects
。报告的基础查询q_TestDatasetExposureEffect
包含一个名为 的字段fldTestsID
。
所以,路径是包含按钮frmSearch
到to 。tabResultsRecord
cmdQAReportResults
frmResultsRecords
fldTestsID
我看到这是同样错误的其他帖子,但没有让它们工作。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