2 reports based on available data

S

Steve G.

I have 2 possible reports (reportA and reportB) that I want to preview using
a button on a form. If there is data available for reportA I would like to
then be able to preview reportA and only reportA. If there is no data
available for reportA I would like to be able to preview reportB and only
reportB. Finally if there is no data available for either I would like to
get a message telling the user that there is no data available. Is this
possible and if it is, how can I make it happen? Thank you.
 
M

Mauricio Silva

It wasn't tested, but it may help:

in your preview buton, put:
Private Sub Command0_Click()
Dim intAux As Integer

intAux = 1 ' Meaning: Report A
DoCmd.OpenReport "Report A Name", acViewPreview

Exit Sub

Print_ReportB:
intAux = 2 ' Meaning: Report B
DoCmd.OpenReport "Report B Name", acViewPreview

Exit Sub

ErrorHandler:
If Err.Number = 2501 Then
If intAux = 1 Then
Resume Print_ReportB
Else
MsgBox "No data to be printed", vbOKOnly + vbExclamation
End If
Else
MsgBox Err.Description, vbOKOnly + vbExclamation
End If

End Sub


in your reports, put in the OnNoData Event:
Cancel = true
 
M

Mauricio Silva

Not testes, but it may help:

In your button_Click event:

Private Sub Command0_Click()
Dim intAux As Integer

intAux = 1 ' Meaning: Report A
DoCmd.OpenReport "Report A Name", acViewPreview

Exit Sub

Print_ReportB:
intAux = 2 ' Meaning: Report B
DoCmd.OpenReport "Report B Name", acViewPreview

Exit Sub

ErrorHandler:
If Err.Number = 2501 Then
If intAux = 1 Then
Resume Print_ReportB
Else
MsgBox "No data to be printed", vbOKOnly + vbExclamation
End If
Else
MsgBox Err.Description, vbOKOnly + vbExclamation
End If

End Sub

in your reports, put in the OnNoData event:
 

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