Macro to Close form if no records exist.

W

Williams

I have a macro that performs many actions. One of the actions is to open a
form and check to see if there are any records. If there are no records then
a MsgBox is displayed. I have done this in the past, and for some reason it
is not working here.

I have an OpenForm action for the form F_Export

then i have a MsgBox action with the following Condition:
[Forms]![F_Export]![Case#] Is Null

If the case number is null, then I have no records to export, so I want the
message box to appear. But for some reason when I run the macro & the form
appears with no records it does not display the MsgBox. Is there a way we
can do this with the count of records feature?
 
S

Steve Schapel

Williams,

I would suggest using a Condition like this for your OpenForm action:
DCount("*","NameOfQuery")>0

Substitute the actual name of the query that the form is based on for
"NameOfQuery".
 
W

Williams

You Rock! Thanks Steve.

Steve Schapel said:
Williams,

I would suggest using a Condition like this for your OpenForm action:
DCount("*","NameOfQuery")>0

Substitute the actual name of the query that the form is based on for
"NameOfQuery".

--
Steve Schapel, Microsoft Access MVP
I have a macro that performs many actions. One of the actions is to open a
form and check to see if there are any records. If there are no records then
a MsgBox is displayed. I have done this in the past, and for some reason it
is not working here.

I have an OpenForm action for the form F_Export

then i have a MsgBox action with the following Condition:
[Forms]![F_Export]![Case#] Is Null

If the case number is null, then I have no records to export, so I want the
message box to appear. But for some reason when I run the macro & the form
appears with no records it does not display the MsgBox. Is there a way we
can do this with the count of records feature?
 

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