This was annoying me. I wanted to display a report showing all of the notes for a student, but it was entirely possible that there would be no notes. Seems simple: put a MSGBOX in the VBA behind the NODATA event of the report. Except the report then tries to display. So I came up with this code:
Private Sub cmdNotesReportPreview_Click() Dim snum As Integer 'student ID Dim sncnt As Integer 'num of notes for this student snum = Forms!frmStudentsSPEDs.StudentID sncnt = DCount("[NoteID]", "dbo_NotesStudents", "StudentID=" & snum) If sncnt > 0 Then DoCmd.OpenReport "rptStudentsNotes", acViewPreview, , "StudentID=" & snum Else MsgBox "This student has no notes to display." End If End Sub
Does the trick for me quite nicely.