A message box when there are no results

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form with a subform. The subform shows the attendance records for a
specified student.

I would like to program the form so that if there are no attendance records
for the chosen student that the subform does not appear as, even with the
record navigation buttons shut off, it contains a blank record and this would
be confusing to end users and could lead to errors as this form is for
editing attendance records.

Thank you in advance for any advice on this matter.
 
Put this code in the main form's Load event procedure:

Me.SubformName.Visible = (Me.SubformName.Form.RecordCount <> 0)

where SubformName is the name of the control that holds the subform.

If you want the subform to become visible/invisible while the form is open
and you're filtering the records, then you'll need to use another event or
procedure for this code, too. Which one depends upon what you might be doing
that would change the number of records in the subform.
 
Thank you for your suggestion Ken.

I have tried what you suggested and it does not seem to work in my
circumstances. The RecordCount argument doesn't seem to be available. I can
use RecordSet or RecordSetClone, but neither will allow for a numberic test.
I need to test for a record count of one, since the subform creates a blank
record for any student with no records in the underlying table. Thus the
IsNull function is no good. Are there any options I could try that you know
of?

Ken Snell said:
Put this code in the main form's Load event procedure:

Me.SubformName.Visible = (Me.SubformName.Form.RecordCount <> 0)

where SubformName is the name of the control that holds the subform.

If you want the subform to become visible/invisible while the form is open
and you're filtering the records, then you'll need to use another event or
procedure for this code, too. Which one depends upon what you might be doing
that would change the number of records in the subform.
 
How about something like:

If Me.SubformName.Form.EOF AND Me.SubformName.Form.BOF Then
Me.SubformName.visible = False
Else
Me.SubformName.visible = True
Endif

This test is more reliable on recordsets than using recordcount anyway.
However, I'm not sure this will work for you in this situation. Give it a
shot and see.

Jim


B. Meincke said:
Thank you for your suggestion Ken.

I have tried what you suggested and it does not seem to work in my
circumstances. The RecordCount argument doesn't seem to be available. I can
use RecordSet or RecordSetClone, but neither will allow for a numberic test.
I need to test for a record count of one, since the subform creates a blank
record for any student with no records in the underlying table. Thus the
IsNull function is no good. Are there any options I could try that you know
of?
 
Sorry... I omitted an important part:

Me.SubformName.Visible = (Me.SubformName.Form.RecordsetClone.RecordCount <>
0)

--

Ken Snell
<MS ACCESS MVP>


B. Meincke said:
Thank you for your suggestion Ken.

I have tried what you suggested and it does not seem to work in my
circumstances. The RecordCount argument doesn't seem to be available. I
can
use RecordSet or RecordSetClone, but neither will allow for a numberic
test.
I need to test for a record count of one, since the subform creates a
blank
record for any student with no records in the underlying table. Thus the
IsNull function is no good. Are there any options I could try that you
know
of?
 
Back
Top