当前位置: 动力学知识库 > 问答 > 编程问答 >

Access 2007, VBA: Error with simple click to open a report

问题描述:

For some reason I'm getting an error on the first line. Everything is named correctly. I used the button creator wizard to open a report I wanted.

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

EDIT: Compile Error: Variable Not Defined

EDIT2: This report is based off a query. Does that matter at all?

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

It's saying syntax error on the DoCmd.OperReport part.

EDIT 4: Working code with syntax solved.

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

网友答案:
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
网友答案:
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
分享给朋友:
您可能感兴趣的文章:
随机阅读: