Macro to Close form if no records exist.

  • Thread starter Thread starter Williams
  • Start date Start date
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?
 
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".
 
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?
 
Back
Top