Help to revise code to open Reports AND Forms.

  • Thread starter Thread starter Denny G.
  • Start date Start date
D

Denny G.

Access 2002. I have code behind a form containing a list
box where when I dbl click on one of the items in the
list, only a report opens using the following code:

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

How can I revise this code to force it to open either/or a
report or a FORM?

The reason I want to do this is that one of my reports has
a date parameter where I need to open a "Query-by-form"
first to input the date range for the subsequent report.
I would appreciate any help. Thank-you
 
Somehow Access has to know which you want to open.

You could include whether or not the item was a report or a form as an
additional column in the listbox. Another method would be to step through the
forms collection and/or the reports collection and see which one had a
form/report with the specified name. Yet another method would be to attempt to
open a report and trap for the error generated if there were no such report and
then attempt to open a form.
 
John, thanks for the reply. I am very inept at writing
VBA code. Do you suppose you could give me a sample of
the code used to ". . . trap for the error generated if
there were no such report and then attempt to open a
form?" Thanks again.



-----Original Message-----
Somehow Access has to know which you want to open.

You could include whether or not the item was a report or a form as an
additional column in the listbox. Another method would be to step through the
forms collection and/or the reports collection and see which one had a
form/report with the specified name. Yet another method would be to attempt to
open a report and trap for the error generated if there were no such report and
then attempt to open a form.

Denny G. said:
Access 2002. I have code behind a form containing a list
box where when I dbl click on one of the items in the
list, only a report opens using the following code:

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

How can I revise this code to force it to open either/or a
report or a FORM?

The reason I want to do this is that one of my reports has
a date parameter where I need to open a "Query-by-form"
first to input the date range for the subsequent report.
I would appreciate any help. Thank-you
.
 
Back
Top