Closing a Report from Code

D

Dan

Hi;

I am developing using XP Professional.

When I open my report, on the open event I check to see
if the user has selected a project. If not, I display an
error message using vbExclamation. This works well.

MY PROBLEM: After the user clicks "OK" from the
vbExclamation box, the report opens anyway with no data.
How do I close the report from code? DoCmd.Close doesn't
work.

Thanks,
Dan
 
F

Fredg

Add
Cancel = True
to the code.

Something like this (change the field names as needed):

Sub Report_Open(etc)
If IsNull([ProjectSelected]) Then
MsgBox "No Project selected."
Cancel = True
Else
'Continue with the report
End If

Note... if the report is opened from a form command button
event, trap for the resulting Err 2501 "You have canceled.. etc.)
in that Button Event's error handling.
 
W

Wayne Morgan

Since you are doing this in the OnOpen event, you just need to set

Cancel = True

and the opening of the report will cancel.
 

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