Access 2007,VBA:单击以打开报表时出错

时间:2013-08-30 18:43:07

标签: vba ms-access-2007

出于某种原因,我在第一行收到错误。一切都正确命名。我使用按钮创建器向导打开我想要的报告。

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:此报告基于查询。这有关系吗?

EDIT3:

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

2 个答案:

答案 0 :(得分:1)

Private Sub cmdReport2013_Click()
On Error GoTo Err_cmdReport2013_Click

docmd.openReport "rptAnalyst_Comp_2013"


Exit_cmdReport2013_Click:
Exit Sub

Err_cmdReport2013_Click:
MsgBox Err.Description
Resume Exit_cmdReport2013_Click

End Sub

答案 1 :(得分:1)

Private Sub cmdReport2013_Click()
Dim stDocName as String

On Error GoTo Err_cmdReport2013_Click

    stDocName = "rptAnalyst_Comp_2013"
    DoCmd.OpenReport (stDocName)


Exit_cmdReport2013_Click:
    Exit Sub

Err_cmdReport2013_Click:
    MsgBox Err.Description
    Resume Exit_cmdReport2013_Click

End Sub