closing a form with no data to display

B

buzz

I saw some posts on this and do not know if I'm running into the same thing.
There's an option on a report that if no data is displayed, I am trying to
utilize the event "On No Data" and use an event procedure. I've gotten it to
half work where it will display the command "MsgBox ("There were no records
founds")" works to give the users a popup box but then I just want the report
to close and not display anything to the user. I cannot get it to close
without displaying the preview format of the output where there's #ERROR
being displayed in all of the fields. Is there anyway to just exit the form?
I couldn't get the DoCmd.Close command to work right.
 
A

Allen Browne

Cancel the report's No Data event, and it never opens.

Just add the line:
Cancel = True
to your code, or use CancelEvent in your macro.

The #Error typically occurs where you have calculated values, such as:
=Sum([Amount])

If you want to show the report but suppress the errors, change the Control
Source to:
=IIf([Report].[HasData], Sum([Amount]), Null)
 
B

buzz

Thanks, that worked perfectly.

Allen Browne said:
Cancel the report's No Data event, and it never opens.

Just add the line:
Cancel = True
to your code, or use CancelEvent in your macro.

The #Error typically occurs where you have calculated values, such as:
=Sum([Amount])

If you want to show the report but suppress the errors, change the Control
Source to:
=IIf([Report].[HasData], Sum([Amount]), Null)

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

buzz said:
I saw some posts on this and do not know if I'm running into the same
thing.
There's an option on a report that if no data is displayed, I am trying to
utilize the event "On No Data" and use an event procedure. I've gotten it
to
half work where it will display the command "MsgBox ("There were no
records
founds")" works to give the users a popup box but then I just want the
report
to close and not display anything to the user. I cannot get it to close
without displaying the preview format of the output where there's #ERROR
being displayed in all of the fields. Is there anyway to just exit the
form?
I couldn't get the DoCmd.Close command to work right.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top