RE: Report No Data
Thanks for the resonces from the original post however I have already done what was suggested. Let me explain again. I created a form called frmDateRange to search a date range specified by the user and display this chosen range on a report (rptDateRange). All the user has to do is enter the beginning and ending dates and click on the Ok button. Behind the Ok button is 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") & "#"
DoCmd.close acForm, Me.Name
End If
End Sub
This will open the report just fine. However if there is no data to display I would like a message box to appear and tell the user there is no data to show and then close the report. I tried this by going to the Reports No_Data and entering this code:
Private Sub Report_NoData(Cancel As Integer)
MsgBox "No Records found for this Date Range." & vbNewLine & _
"Report will now close. Please try another.", vbInformation
Cancel = True
End Sub
When I do this I get this Error:
Run-time error '2501':
The OpenReport action was canceled.
You used a method of the DoCmd object to carry out an action in Visual Basic, but then clicked Cancel in a dialog box. For example, you used the Close method to close a changed form, then clicked Cancel in the dialog box that askes if you want to save the changes you made to the form.
Then it highlights the Else: code in my frmDateRange. I understand what the error is saying, but I don't know how to get around it. Thanks in advance.
Thanks for the resonces from the original post however I have already done what was suggested. Let me explain again. I created a form called frmDateRange to search a date range specified by the user and display this chosen range on a report (rptDateRange). All the user has to do is enter the beginning and ending dates and click on the Ok button. Behind the Ok button is 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") & "#"
DoCmd.close acForm, Me.Name
End If
End Sub
This will open the report just fine. However if there is no data to display I would like a message box to appear and tell the user there is no data to show and then close the report. I tried this by going to the Reports No_Data and entering this code:
Private Sub Report_NoData(Cancel As Integer)
MsgBox "No Records found for this Date Range." & vbNewLine & _
"Report will now close. Please try another.", vbInformation
Cancel = True
End Sub
When I do this I get this Error:
Run-time error '2501':
The OpenReport action was canceled.
You used a method of the DoCmd object to carry out an action in Visual Basic, but then clicked Cancel in a dialog box. For example, you used the Close method to close a changed form, then clicked Cancel in the dialog box that askes if you want to save the changes you made to the form.
Then it highlights the Else: code in my frmDateRange. I understand what the error is saying, but I don't know how to get around it. Thanks in advance.