Mark
asked on
How to detect empty Record Source in report detail_format()?
I have a report where I have a detail_format routine to do some additional formatting of the detail lines. This works just fine as long as the record source has rows. However, the user is able to select date ranges, etc in such a way as to result in no rows in the record source query. I would think that Access would never call the detail_format() routine, but it does. The first reference to a bound object causes the report to blow up with: "The Output To action was canceled". In the debugger, it indicates "You entered and expression that has no value" and the debug line highlights the 1st reference to a bound object.
I won't bother asking why Access goes ahead and calls the detail_format() function with no data. What I would like to know is 1) what is the proper way to detect an empty record source in the detail_format() function and 2) how do I gracefully exit (what does the Cancel parameter do? I haven't quite figured this out. I've looked in the MS Access VBA Reference, but can't locate detail_format() under methods, events or functions).
I won't bother asking why Access goes ahead and calls the detail_format() function with no data. What I would like to know is 1) what is the proper way to detect an empty record source in the detail_format() function and 2) how do I gracefully exit (what does the Cancel parameter do? I haven't quite figured this out. I've looked in the MS Access VBA Reference, but can't locate detail_format() under methods, events or functions).
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I chose your first solution because I do want to tell the user there is no date. Thanks.
so if u ignore error number 2501, u should be okay
eg
On Error GoTo ReportLoad_Error
DoCmd.OpenReport "myreport", acViewPreview
Exit Sub
ReportLoad_Error:
If Err.Number <> 2501 Then MsgBox Err.Description