Aggregate values in three text boxes (1 Viewer)

pinky

Registered User.
Local time
Today, 02:57
Joined
Jul 6, 2009
Messages
29
Hi,
I have three text boxes txt1, txt2, txt3, txt4. I want to set
txt4 = txt1+txt2+txt3.
I could set txt3 control source as [txt1]+[txt2]+[txt3]. But if there is no value is entered in txt2 then it is not calculating sum. Whether or not text boxes are entered value i want to calculate the sum and display in txt4.

Can anyone help me with this issue. Thanks in advance.

Thanks,
pinky
 

Voltron

Defender of the universe
Local time
Today, 04:57
Joined
Jul 9, 2009
Messages
77
Set the default values of the textboxes to 0.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 02:57
Joined
Aug 30, 2003
Messages
36,133
Try

=Nz(txt1, 0)+Nz(txt2, 0)+Nz(txt3, 0)
 

pinky

Registered User.
Local time
Today, 02:57
Joined
Jul 6, 2009
Messages
29
Thank you for replying so soon.

I tried both ways which make my text boxes default to zero before i start entering which i dont want. The requirement is that text boxes should be blank initially and when we type in only in 2 text boxes or 3, it should calculate the total in txt4. This makes user to identify that there is no third value existing. How to use lost focus in this scenario.

By default textboxes should be blank. when I start entering values in txt1 and txt2 , skip txt3 and tab to txt4 then it should calculate the sum of above txt boxes.

Thanks,
Pinky
 

Mike375

Registered User.
Local time
Today, 19:57
Joined
Aug 28, 2008
Messages
2,548
A simple way would be to make 3 extra text boxes and hide them.

Put in each text box

IIF([Text1] Is Null,0,[Text1]) etc.

Then make Text4 the sum of the 3 hidden text boxes.
 

pinky

Registered User.
Local time
Today, 02:57
Joined
Jul 6, 2009
Messages
29
Thank you for helping me out.
I have written got focus event procedure with the below expression. It is not working.
I added three extra textboxes txt5, txt6, txt7. and each control source was set to IIF([Txt1] Is Null,0,[Txt1]); IIF([Txt2] Is Null,0,[Txt2]);
IIF([Txt3] Is Null,0,[Txt3]). It is also not working.

Let me know how to exactly use IsNull(Is Null) and resolve this issue.

thanks,
Pinky
 

Scooterbug

Registered User.
Local time
Today, 05:57
Joined
Mar 27, 2009
Messages
853
To check for a null value, its:

IsNull([Txt3]), not [Txt3] is Null
 

Brianwarnock

Retired
Local time
Today, 10:57
Joined
Jun 2, 2003
Messages
12,701
=IIF([Txt3] Is Null,0,[Txt3])
is a perfectly valid construct for a control source of a textbox and does work

Brian
 

boblarson

Smeghead
Local time
Today, 02:57
Joined
Jan 12, 2001
Messages
32,059
I still would use the NZ function that Paul suggested. However, I do believe you need to use square brackets in a control source:

=Nz([txt1], 0) + Nz([txt2], 0) + Nz([txt3],0)
 

boblarson

Smeghead
Local time
Today, 02:57
Joined
Jan 12, 2001
Messages
32,059
The system will insert them for valid objects.

Brian
Brian:
Unfortunately, not 100% of the time, at least that I've found. It SHOULD put them there, but it needs to be verified that they were there when the OP tried the code Paul gave.

Pinky:
I would suggest posting the EXACT formula you tried when you tried Paul's suggestion
 

Mike375

Registered User.
Local time
Today, 19:57
Joined
Aug 28, 2008
Messages
2,548
Pinky

The problem was probably no = sign before the formula.

The = sign always into an unbound text box. A query field that is made from a formula does not have the = sign.
 

Users who are viewing this thread

Top Bottom