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

  • Thread starter Thread starter Zoe Norleen
  • Start date Start date
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
 
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
 
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.
 
Back
Top