Report No Data

jefrat72

New member
Local time
Today, 10:26
Joined
Mar 8, 2001
Messages
5
I created a form to allow users to create a report based on a date range. I did so using this code:
Private Sub cmdOk_Click()

If IsNull(Me.txtStartDate) Or IsNull(Me.txtEndDate) Then
MsgBox "Both dates are required for this search!", vbInformation
Else: DoCmd.OpenReport "rptDateRange", acViewPreview, , _
"[RequestDate] Between #" & Format(Me.txtStartDate, "mm\/dd\/yyyy") _
& "# And #" & Format(Me.txtEndDate, "mm\/dd\/yyyy") & "#"
End If

End Sub

However, I would like to display a message when there is no data found in the given date range that would tell the user there is no data found and then close the report and return to the form. I have put this MsgBox in the Report No_Data but get an error because it is interferring with Else code in the form. Can anyone help me with the code to combine the two to rid myself of this error? Thanks in advance.
 
Use the on NoData event for the report.
 
This is the code to use on the OnNoData property on the Event tab for the report. I found this code on another post in the archives here, and successfully included it in my database this morning.


' This code displays a message box to let
' the user know there is no data for report

MsgBox "Sorry, there is no data for this report.", 0, "No Data Available"

' This code cancels the report

Cancel = True
 

Users who are viewing this thread

Back
Top Bottom