How to inhibit a form from opening when there are no records?

Z

Zoe Norleen

I have a form that is populated from a query. When there
are no records presented by the query, I do not want the
form to open. A message box that states "no records meet
the criteria...." would be nice, but at this point, all I
want to do is have it not open (because it's blank and has
no controls, etc.)
Any assistance is greatly appreciated,
Zoe
 
W

Wayne Morgan

In the Form's OnOpen event, do a DCount on the query. If the result is zero, display your
message and Cancel the open. This may give you Error 2501 (I think the number is correct)
in the procedure that opened the form. The error states something like "The action was
canceled". You will need to trap this in the error handler of the calling procedure.

If DCount("*", Me.Recordsource) = 0 Then
'MsgBox Here
Cancel = True
End If
 
Z

Zoe Norleen

Thank you so much!
It worked perfectly!
-----Original Message-----
In the Form's OnOpen event, do a DCount on the query. If
the result is zero, display your
message and Cancel the open. This may give you Error 2501
(I think the number is correct)
in the procedure that opened the form. The error states something like "The action was
canceled". You will need to trap this in the error
handler of the calling procedure.
 

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