Help revising code.

D

Denny G.

Access 2002. The code that follows opens reports only.
Since I am a beginner at writing code, will one of you
experts show me the code I need to make this code open
both REPORTS and FORMS? Thank-you.

Private Function Preview()
On Error GoTo Preview_Err

If IsNull([ReportsList]) Or [ReportsList] = "" Then
MsgBox "You must select a report", 16, "Error"
DoCmd.GoToControl "ReportsList"
Exit Function
End If

DoCmd.OpenReport Me![ReportsList].Column(2),
acViewPreview
DoCmd.Maximize

Preview_Exit:
Exit Function

Preview_Err:
Select Case Err
Case 2501
Case 2202
MsgBox Error$
Case Else
MsgBox "Previewing report was Cancelled",
0, "Notice"
End Select
Resume Preview_Exit

End Function
 
J

John Spencer (MVP)

Private Function Preview()
On Error GoTo Preview_Err

If IsNull([ReportsList]) Or [ReportsList] = "" Then
MsgBox "You must select a report", 16, "Error"
DoCmd.GoToControl "ReportsList"
Exit Function
End If

DoCmd.OpenReport Me![ReportsList].Column(2),
acViewPreview
DoCmd.Maximize

Preview_Exit:
Exit Function

Preview_Err:
Select Case Err
Case 2103 'No report to open with this name
Docmd.OpenForm Me.ReportsList.Column(2) 'Plus any other
Resume next

Case 2501
Case 2202
MsgBox Error$
Case Else
MsgBox "Previewing report was Cancelled",
0, "Notice"
End Select
Resume Preview_Exit

End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top