Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Report won't run with no Data

Status
Not open for further replies.

Castanz

Programmer
Apr 5, 2002
61
US
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.

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
 
If I take the
Code:
Cancel = True
out it works fine and opens a blank report. Why does the NoData subroutine declare "Cancel As Integer"?

 
what SP's are installed

HTH << MaZeWorX >> "I have not failed I have only found ten thousand ways that don't work" <<Edison>>
 
[q] Why does the NoData subroutine declare "Cancel As Integer"?[/q]
Cancel = True
"True" is a reserved word that evaluates to -1 in VBA.

Beir bua agus beannacht!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top