How do I create a message box for a report if there are no record.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am using Access 2000 and have reports which possibly have no results to the
respective query. The report will display #error because the result set is
empty. I would instead like to display an information box stating that "There
are no outstanding stars to be distributed".
 
I am using Access 2000 and have reports which possibly have no results to the
respective query. The report will display #error because the result set is
empty. I would instead like to display an information box stating that "There
are no outstanding stars to be distributed".

In the Report's OnNoData event:
MsgBox "There are no available records for this report."
Cancel = true

The above code will create a #2501 error if the report was opened from
a code event.

You have to trap for Error 2501 in the event that started the whole
process:

On Error Goto Err_Handler
DoCmd.OpenReport "FormName", acViewPreview

Exit_This_Sub:
Exit Sub

Err_Handler:
If Err = 2501 Then
Else
MsgBox "Error #: " & Err.Number & " " & Err.Description
End If
Resume Exit_This_Sub
End Sub
 
Back
Top