#Error in Main/SubForm

  • Thread starter Thread starter SF
  • Start date Start date
S

SF

I have a main and subform link together with ContactID field. On the main
form I put a text filed called 'Total' to show the sum of purchase enlisted
in the subform. I notice that when there is no data in the subform the Total
Field show #Error.

Is there a way to show Zero or blank instead of #Error?

Thank

SF
 
Does the Detail section of your subform go completely blank when there are
no records? It does that if new records cannot be added (e.g. if its
AllowAdditions property is No, or it uses a read-only query as its source.)

You might solve the problem by setting AllowAddtions to Yes for the subform.
Cancel its BeforeInsert event if you want to block new entries.

The alternative is to test if the subform has records. This example assumes
a subform control named Sub1, with a text box named txtTotal:
=IIf([Sub1].Form.RecordsetClone.RecordCount = 0, 0,
Nz([Sub1].Form!txtTotal,0))
 
Thank you. It works!

SF

Allen Browne said:
Does the Detail section of your subform go completely blank when there are
no records? It does that if new records cannot be added (e.g. if its
AllowAdditions property is No, or it uses a read-only query as its source.)

You might solve the problem by setting AllowAddtions to Yes for the subform.
Cancel its BeforeInsert event if you want to block new entries.

The alternative is to test if the subform has records. This example assumes
a subform control named Sub1, with a text box named txtTotal:
=IIf([Sub1].Form.RecordsetClone.RecordCount = 0, 0,
Nz([Sub1].Form!txtTotal,0))

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

SF said:
I have a main and subform link together with ContactID field. On the main
form I put a text filed called 'Total' to show the sum of purchase
enlisted
in the subform. I notice that when there is no data in the subform the
Total
Field show #Error.

Is there a way to show Zero or blank instead of #Error?
 
Back
Top