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.
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.