IF report has records then execute code

jv2

Registered User.
Local time
Today, 23:42
Joined
Aug 9, 2004
Messages
34
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!
 
does your version of Access has an event OnNoData in the Report Properties ?
 
no... it doesn't. :(
 
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
 
I really dont think it does... :(

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

report-events.bmp
 
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
 

Users who are viewing this thread

Back
Top Bottom