T
Tony Williams
I have a macro that runs if there is no data for a report that is based on a
macro. The macro is on the OnNodata property of the report and pops up a
message to the user that there sre no records, but when I click on the OK
button of the message I get an error message that says
Runtime error 2501
The OpenReportaction was cancelled
On pressing debug it takes me to the Docmd OpenReport line at the end of the
code which is behind a command button on my report prompt form. Here is my
code
Private Sub cmdOK_Click()
Dim strReport As String 'Name of report to open.
Dim strField As String 'Name of your date field.
Dim strWhere As String 'Where condition for OpenReport.
Const conDateFormat = "\#mmmm\/yyyy\#"
strReport = "rptsense3"
strField = "txtMonthlabel"
If Not IsNull(txtMonthlabel) Then
If IsNull(Me.txtstartdate) Then
MsgBox "You must enter a start date", vbOKOnly, "Missing Start Date"
Me.txtstartdate.SetFocus
Else
If IsNull(Me.txtenddate) Then
MsgBox "You must enter an end date", vbOKOnly, "Missing End Date"
Me.txtenddate.SetFocus
Else
strWhere = strField & " Between " & Format(Me.txtstartdate,
conDateFormat) _
& " And " & Format(Me.txtenddate, conDateFormat)
If Not IsNull(Me.cmbselectcompany) Then
strWhere = strWhere & " AND cmbCompany = """ & Me.cmbselectcompany & """"
End If
DoCmd.OpenReport strReport, acViewPreview, , strWhere
End If
End If
End If
End Sub
How can I change my code so that I don't get this message
macro. The macro is on the OnNodata property of the report and pops up a
message to the user that there sre no records, but when I click on the OK
button of the message I get an error message that says
Runtime error 2501
The OpenReportaction was cancelled
On pressing debug it takes me to the Docmd OpenReport line at the end of the
code which is behind a command button on my report prompt form. Here is my
code
Private Sub cmdOK_Click()
Dim strReport As String 'Name of report to open.
Dim strField As String 'Name of your date field.
Dim strWhere As String 'Where condition for OpenReport.
Const conDateFormat = "\#mmmm\/yyyy\#"
strReport = "rptsense3"
strField = "txtMonthlabel"
If Not IsNull(txtMonthlabel) Then
If IsNull(Me.txtstartdate) Then
MsgBox "You must enter a start date", vbOKOnly, "Missing Start Date"
Me.txtstartdate.SetFocus
Else
If IsNull(Me.txtenddate) Then
MsgBox "You must enter an end date", vbOKOnly, "Missing End Date"
Me.txtenddate.SetFocus
Else
strWhere = strField & " Between " & Format(Me.txtstartdate,
conDateFormat) _
& " And " & Format(Me.txtenddate, conDateFormat)
If Not IsNull(Me.cmbselectcompany) Then
strWhere = strWhere & " AND cmbCompany = """ & Me.cmbselectcompany & """"
End If
DoCmd.OpenReport strReport, acViewPreview, , strWhere
End If
End If
End If
End Sub
How can I change my code so that I don't get this message