handling empty subforms?

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?

some more notes: when I enter the following code
(=[subformControl].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??

(and I'm using Microsoft Access 2000)

thanks
Jerome
 
J

Jerome

Yes, I've posted the original message in 'queries', but the problem
isn't really solved.

1. the first method works only if I'd want to count ALL records on the
subform (but I need the total of a selection of those records)
2. the second method (.HasData) would be great but I always get a #name?
error

So because it seems to be a forms-related problem I permitted myself to
post an updated question here in this forum and hoped someone else could
offer a new solution.
 
J

Jerome

Problem solved, I got the solution in a different newsgroup:
*******************************************************************************
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.
*****************************************************************************
 

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