Hi
This code works fine when the query produces data. When the query produces no data I get, "No orders for this date.", "Microsoft Office Access has encountered a problem and needs to close". Then I get dumped out of Access.
I have seen error 2501 traps, but I don't seem to be getting an error. I put the line "MsgBox Err.Number", but I am never presented with an error.
I have Access 2007. Any help would be appreciated.
This code works fine when the query produces data. When the query produces no data I get, "No orders for this date.", "Microsoft Office Access has encountered a problem and needs to close". Then I get dumped out of Access.
I have seen error 2501 traps, but I don't seem to be getting an error. I put the line "MsgBox Err.Number", but I am never presented with an error.
I have Access 2007. Any help would be appreciated.
Code:
Private Sub Report_NoData(Cancel As Integer)
MsgBox "No orders for this date.", vbExclamation
Cancel = True
End Sub
Code:
Private Sub Previeworders_Click()
On Error GoTo Err_Previeworders_Click
Dim stDocName As String
Dim StrMeal, strCommand, strDate As String
StrMeal = Me.Meal.Value
strCommand = Me.Command.Value
strDate = Me.DateofOrder.Value
stDocName = "IndvCommandMeal_rpt"
StrWhereCond = "Meal='" & StrMeal & "'" & " And " & "Command='" & strCommand & "'"
StrWhereCond = StrWhereCond & " And " & "DateofOrder >= #" & strDate & "#"
DoCmd.OpenReport stDocName, acViewPreview, , Wherecondition:=StrWhereCond
MsgBox Err.Number
Exit_Previeworders_Click:
Exit Sub
Err_Previeworders_Click:
MsgBox Err.Description
Resume Exit_Previeworders_Click
End Sub