How to test for no data

B

Bernie

I am trying to test for no data, so I can display an appropriate message when
there is no data. Also, I am currently getting an error, because I am trying
to set a variable, but there is no data.
 
F

fredg

I am trying to test for no data, so I can display an appropriate message when
there is no data. Also, I am currently getting an error, because I am trying
to set a variable, but there is no data.

Well, I guess you are doing this on a form.

Code the form's Open event:
If Me.RecordsetClone RecordCount = 0 Then
MsgBox "No records found."
Cancel = True
End If

If there is no data, the message will appear.
The form itself will not open.
Remove
Cancel = True
if you wish the form to open anyway, without records.
 
Top