default value with calculated field

  • Thread starter Thread starter Les Coover
  • Start date Start date
L

Les Coover

MS Access 2000

On a form 3 fields: txtA, txtB, txtC

I use the control source property to create a calculated field
=[txtA]+[txtB]+[txtC] and name the calculated field SumIt.

Fine and dandy, everything works as long as I enter a NUMBER or ZERO in each
of the 3 fields.

But, I would like SumIt to add the fields together even when there is
nothing entered in one or two of the fields.

So my form will look better, so I won't have to look at a bunch of
zeros--just nice empty blank spaces when nothing is entered.

Well I tried making the default value in the table an empty string and a
null string but neither worked. Of cource I could make
the default value zero but this is where you came in--I want to get rid of
the zeros.

Anyone know how I can use my calculated field and not have to see zeros in
the fields where nothing is entered?

Thanks,

Les
 
Thanks, the answer was right in front of me on a help screen, I appreciate
your help
and please excuse my impatience.

Examples of performing arithmetic operations in forms, reports, and data
access pages

When you use an arithmetic operator (+, -, *, /) in an expression, and the
value of one of the controls in the expression is Null, the result of the
entire expression will be Null. On a form or report, if some records in one
of the controls that you used in the expression might have a Null value, you
can convert the Null value to zero by using the Nz function; for example:
=Nz([Subtotal])+Nz([Freight])

Les

Van T. Dinh said:
Try:

=Nz([txtA], 0) + Nz([txtB], 0) + Nz([txtC], 0)

--
HTH
Van T. Dinh
MVP (Access)



Les Coover said:
MS Access 2000

On a form 3 fields: txtA, txtB, txtC

I use the control source property to create a calculated field
=[txtA]+[txtB]+[txtC] and name the calculated field SumIt.

Fine and dandy, everything works as long as I enter a NUMBER or ZERO in each
of the 3 fields.

But, I would like SumIt to add the fields together even when there is
nothing entered in one or two of the fields.

So my form will look better, so I won't have to look at a bunch of
zeros--just nice empty blank spaces when nothing is entered.

Well I tried making the default value in the table an empty string and a
null string but neither worked. Of cource I could make
the default value zero but this is where you came in--I want to get rid of
the zeros.

Anyone know how I can use my calculated field and not have to see zeros in
the fields where nothing is entered?

Thanks,

Les
 
Back
Top