出于某种原因,我在第一行出现错误。一切都正确命名。我使用按钮创建向导打开了我想要的报告。
Private Sub cmdReport2013_Click()
On Error GoTo Err_cmdReport2013_Click
stDocName = "rptAnalyst_Comp_2013"
Exit_cmdReport2013_Click:
Exit Sub
Err_cmdReport2013_Click:
MsgBox Err.Description
Resume Exit_cmdReport2013_Click
End Sub
编辑:编译错误:未定义变量
EDIT2:此报告基于查询。这有关系吗?
编辑3:
Private Sub cmdReport2013_Click()
Dim stDocName As String
On Error GoTo Err_cmdReport2013_Click
stDocName = "rptAnalyst_Comp_2013"
DoCmd.OpenReport (stDocName, acViewNormal)
Exit_cmdReport2013_Click:
Exit Sub
Err_cmdReport2013_Click:
MsgBox Err.Description
Resume Exit_cmdReport2013_Click
End Sub
这是说 DoCmd.OperReport 部分的语法错误。
编辑 4:解决了语法的工作代码。
Private Sub cmdReport2013_Click()
Dim stDocName As String
On Error GoTo Err_cmdReport2013_Click
stDocName = "rptAnalyst_Comp_2013"
DoCmd.OpenReport stDocName, acViewReport
Exit_cmdReport2013_Click:
Exit Sub
Err_cmdReport2013_Click:
MsgBox Err.Description
Resume Exit_cmdReport2013_Click
End Sub