The crucial thing is to understand what is causing the error.
Examples of possibilities:
1. The subform has no records and new records cannot be added. In this case,
the subform's detail section goes completely blank, and any reference to the
non-existent text box causes an error.
The solution would be something like this:
=IIf([MySub].[Form].[RecordsetClone].[RecordCount] = 0, 0,
Nz([MySub].[Form].[Text0],0))
2. Malformed statement.
If your text box contains something like this:
=DLookup("MyField", "MyTable", "[Field2] = " & [Field2])
you are asking Access to concatenate the value of Field2 into the 3rd
argument. But if Field2 is null (e.g. at a new record), the 3rd argument
becomes just:
[Field2] =
which is clearly mal-formed. To avoid this, add Nz(), e.g.:
=DLookup("MyField", "MyTable", "[Field2] = " & Nz([Field2],0))
3. Other error
A simple statment like:
=[Field1] / [Field2]
generates an error when Field2 is zero. (Divide by zero error).
Solution:
=IIf([Field2]=0, 0, [Field1] / [Field2])
Again, there are heaps of way to generate an error: even setting a control's
Format property to Short Date and then entering any text that is not a date.
So, figure out what is causing the error, and you know how to solve it.
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Reply to group, rather than allenbrowne at mvps dot org.
MSA said:
My form has a subform and I have a a text box on the main form which is
showing the total value from the footer of the subform.
When the form is opened initially the Tesxt box by default always displays
"#Error" in the text box.
Is there a way I can suppress or have it default to "0" instead?