Checking for Empty Table

  • Thread starter Thread starter rkbrown04
  • Start date Start date
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?
 
In the Open event:
If Me.Recordset.EOF Then
'Whatever if empty
Else
'Whatever when not empty
End If
 
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
 
Back
Top