forms and HasData?

  • Thread starter Thread starter Jerome
  • Start date Start date
J

Jerome

Hi there,

I've got trouble with a subform: I want to check whether it has any
records or not and do something depending on it. Somebody now suggested
I'd do that with the following code: =IIf(subformControl.Form.HasData,
subformControl.Form.txtFromSub, 0), but somehow that doesn't work since
I always get a #name? error! And the names seem to be right!?

Anyone have any ideas what could be wrong or how I could otherwise test
if a subform has any records at all?

Thanks a lot.

Jerome
 
some more info:

when I enter the following code (=[mysubform].Form!noAtt) as the
datasource into an unbound field on my main form, everything works
alright EXCEPT it displays an #error when the subform doesn't contain a
record. What code is needed so the unbound field doesn't display #error
but 0 instead??

thanks
 
The HasData property applies to reports, not forms.

Try:
= IIf([mysubform].Form.RecordsetClone.RecordCount = 0, 0,
[mysubform].Form!noAtt)

Another alternative would be to use IsError() inside IIf().

In general, you only need to worry about this issue if records cannot be
added to the subform (e.g. its RecordSource is read only, or its
AllowAdditions property is No). If not, the subform goes completely blank
when there are no records to display (since it cannot show the new record),
and so attempting to refer to the non-existent control causes the error.
 
Back
Top