Unanswered: On No Data event - Stop Macro in VBA???
I have a macro that has another macro embedded to print preview a report. On this print macro, I need the print macro to stop if there is no data in the report. I have placed a stop macro in the On No Data event but it only stops the stop macro not the print macro. So I am thinking that I need to put some code in the On No Data event to stop the print macro which would allow it to go back to the original macro and finish. I am no VBA programmer so I am asking for the assistance of somebody in the know!
I received your email from ages ago only today (I don't use that account much...) - if you need to contact me best to PM me Anyway - wasn't ignoring you.
I generally handle this with some code in the report open event. Check the Me.HasData property. If it returns false then set a public property (e.g. called Quit) for the form (or a global variable if that sounds galling) to True. Have the calling code check the property\ variable after opening the report and kill it if there is no data. Reason I do it this way is that setting the OnOpen argument Cancel to true results in a error in the calling procedure.
I would love to hear a more elegant solution though.
I have several reports like this also, but I use the
If Dcount("RecordID","SalesOrders","[InvoiceTotal]>='1000'")=0 then
response=msgbox("No records found", vbOKOnly + vbExclamation,"No Records Found")
just before the call to open the report to tell me there are no records and then exit sub