Checking for Empty Table

R

rkbrown04

I have a form that is a continuous form and occasionally the table that the
forms data comes from is empty. I have code in the Form_Load procedure that
is executed and causes an error because there is no data in the table. Is
there a way to test for the absence of data before I test values in the
record. The nz(me.id,"xxx") is not working because me.id is not valid there
is no record. I get an error message that says I have entered an expression
that has no value. Any ideas?
 
T

tedmi

In the Open event:
If Me.Recordset.EOF Then
'Whatever if empty
Else
'Whatever when not empty
End If
 
D

Dale Fye

If you don't even want to open the form if there is no data, then you could
use DLOOKUP to determine whether there is at least one record in the table,
something like:

Private Sub cmd_OpenForm_Click

if ISNULL(DLOOKUP("[ID]", "Your Table")) Then
'don't open the form
else
docmd.openform "yourForm", ....
end if

end sub

I would use DLOOKUP rather than DCOUNT because it will return the value of
the [ID] field in the first record of the table, which would be a lot quicker
than DCOUNT.

HTH
Dale
 
M

Marshall Barton

rkbrown04 said:
I have a form that is a continuous form and occasionally the table that the
forms data comes from is empty. I have code in the Form_Load procedure that
is executed and causes an error because there is no data in the table. Is
there a way to test for the absence of data before I test values in the
record.


Another way:

If Me.Recordset.RecordCount > 0 Then
 

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