Make label visible if recordsetclone.count is 0

  • Thread starter Thread starter George Avery
  • Start date Start date
G

George Avery

Forgive the second post but I just cannot get this to work.

I want to make a label visible only if a form has no
records to display. I am opening the form using code
behind a button on another form to filter records based on
the currently logged on (domain not database) user. I have
tested that the filter works and is providing the results
I want. The label will tell the user that the form is
blank because there are no records so that they don't
think there's a problem.

In a previous post this was suggested -
In the Form's Open event:
LBL_info.Visible = Me.RecordsetClone.RecordCount =0

- but this doesn't work. Can someone please help me out.

Thanks - GA
 
The form's recordset isn't available in the Open event (too early), you need
to use the Load event. Also, creating a clone of the recordset without
moving to the end of the recordset won't give you an accurate count,
although since you're only testing for zero, not the total number of
records, I would still expect it to work. However, if it causes you
problems, you may want to try:

LBL_info.Visible = Me.Recordset.RecordCount =0

Whether or not the recordset is directly available this way will depend on
your version of Access. The other option would be:

LBL_info.Visible = Me.RecordsetClone.BOF And Me.RecordsetClone.EOF

If you are at the beginning and end of the recordset at the same time, then
there are no records.
 
George,

Try putting your code on the Load event rather than the Open event.

I would personally prefer to use Domain Aggregate Function for this, i.e.
Me.LBL_info.Visible = DCount("*","MyQuery") = 0
.... where MyQuery is the name of the form's Record Source.
 
Back
Top