IIf function ....HasData

G

Guest

Can the IIf function with HasData be used as a control source for a text box
on a form. I use the same statement on a report and it works fine.

=IIf([query1 subform].Form.HasData,[query1
subform].Form!Value,0)+IIf([query2 subform].Form.HasData,[query2
subform].Form!Value2,0).

The calculation works without the IIf statement but I need to check for
fields with no data.
 
A

Allen Browne

Forms don't have a HasData property.

Unless the subform cannot display the new record, you don't need to worrry
about it. Just use Nz():
=Nz([query1 subform].Form![Text0],0)
+ Nz([query2 subform].Form![Text1],0)
Substitute the names of your test boxes for Text0 and Text1.

If the form cannot show the new record (read-only query, or AllowAdditions
set to No), test the RecordCount of the RecordsetClone of the subform:
=IIf([query1 subform].Form.RecordsetClone.RecordCount > 0,
Nz([query1 subform].Form![Text0],0), 0)
+ ...
 

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