View Full Version : IF report has records then execute code


jv2
09-02-2004, 02:43 AM
hello again...

Im running access 2.0 (yuck... I know)

I have the following in one of report footers...

If [MonthClosingStock] <= [MinStockLevel] Then
[Warning].Visible = True
Else
[Warning].Visible = False
End If

How would I run this code only if the report has records? Because at the moment if the user selects a future month by mistake, the report doesnt open as it just diaplys the code window and says that monthClosingStock has no value....

Thanks for your help!

maxmangion
09-02-2004, 04:51 AM
does your version of Access has an event OnNoData in the Report Properties ?

jv2
09-02-2004, 05:25 AM
no... it doesn't. :(

Rich
09-02-2004, 01:45 PM
I'll bet it does, look on the Property sheet for the Report under the Event tab

add the following procedure, something like

Private Sub Report_NoData(Cancel As Integer)
' Display a message if user enters a date for which there are no records,
' and don't preview or print report.

Dim strMsg As String, strTitle As String
Dim intStyle As Integer

strMsg = "You must enter a date between 10-Aug-94 and 5-Jun-96."
intStyle = vbOKOnly
strTitle = "No Data for Date Range"

MsgBox strMsg, intStyle, strTitle
Cancel = True

End Sub

jv2
09-03-2004, 01:19 AM
I really dont think it does... :(

Have a look at the pic... is this what you mean?

http://www.geocities.com/jv2jv2/report-events.bmp

jv2
09-03-2004, 02:12 AM
nevermind.... worked around it with a bit of error handling...
should have thought of it earlier :)

On Error GoTo Err_lblFormat

If [MonthClosingStock] <= [MinStockLevel] Then
[Warning].Visible = True
Else
[Warning].Visible = False
End If

Exit_lblFormat:
Exit Sub
Err_lblFormat:
MsgBox ("You have selected a month which has no data in it...")
Resume Exit_lblFormat

End Sub