Formula in Access (1 Viewer)

S

second_existenc

Guest
Ok so I'm kinda new to access. What i want to happen is for there to be a textbox on a form that changes depending on what is in the other text boxes. Eg 1st box = 1, 2nd box = 2. I want the third box to equal the ammount of the first two added together (textbox1 + textbox2 = textbox3) how do i do it? Where do i put the formula. Thanks.
 

Smart

Registered User.
Local time
Today, 19:38
Joined
Jun 6, 2005
Messages
436
RE: Formula in access

1st box = 1, 2nd box = 2. I want the third box to equal the ammount of the first two added together (textbox1 + textbox2 = textbox3) how do i do it? Where do i put the formula. Thanks.

in the after update of 2nd box write this code
nameof3rdbox = namof1stbox + nameof2ndbox

You might want validation before performing the addition
ie making sur a value is in 1stbox and 2nd box

Hope this helps
 

Mile-O

Back once again...
Local time
Today, 19:38
Joined
Dec 10, 2002
Messages
11,316
In the third textbox's ControlSource you can put:

Code:
=Nz([txtBox1]) + Nz([txtBox2])

To be extra cautious, you may consider using the IsNumeric() function to test that the values are numbers.
 

Ron_dK

Cool bop aficionado
Local time
Today, 20:38
Joined
Sep 5, 2002
Messages
2,141
Other solution if you want a permanent sum :

Base your form on a query and add this field to your query :

Code:
Total : Nz([field1])+Nz([field2])

Field1 and field2 are the fields coming from the table that you based your query on. Insert the 'Total' as a new field on your form.
 

ScottGem

Registered User.
Local time
Today, 14:38
Joined
Jun 20, 2005
Messages
1,119
rak said:
Other solution if you want a permanent sum :

Base your form on a query and add this field to your query :

Code:
Total : Nz([field1])+Nz([field2])

Field1 and field2 are the fields coming from the table that you based your query on. Insert the 'Total' as a new field on your form.

I disagree with this. As a general rule calculated values should NOT be stored. You can display the results of the calculation anytime you want using the expression. Storing calculated values leads to inaccuracy and denormalization.
 

Ron_dK

Cool bop aficionado
Local time
Today, 20:38
Joined
Sep 5, 2002
Messages
2,141
Scottgem,

Correct me if I am wrong, but by using a query that calculates a value,
you only display the ( calculated) value. The query does NOT store the data/value in a table.
I don't see anything wrong with that.
I've been thru almost all threads on storing calulated data on this forum and
learned that storing data or the misuse of that is related to storing data in TABLES.
Again, the (select ) query I proposed gives one a view of the calculated value. Same like the textbox thing would do.
 

Mile-O

Back once again...
Local time
Today, 19:38
Joined
Dec 10, 2002
Messages
11,316
I agree with you, rak. I think ScottGem has misread your post.
 

Mile-O

Back once again...
Local time
Today, 19:38
Joined
Dec 10, 2002
Messages
11,316
rak said:
Insert the 'Total' as a new field on your form.

I'm sure what you meant was bind the total from the query to a new textbox on your form. ;)
 

Ron_dK

Cool bop aficionado
Local time
Today, 20:38
Joined
Sep 5, 2002
Messages
2,141
SJ McAbney said:
I'm sure what you meant was bind the total from the query to a new textbox on your form. ;)

Exactly SJ.
I realize that I have to be more accurate in my wording. Will remember that.


Cheers, Ron
 

ScottGem

Registered User.
Local time
Today, 14:38
Joined
Jun 20, 2005
Messages
1,119
I apologize. I did misread your note. I thought you were advocating add a field to a table, not a column to a query or a control on a form.

Scott<>
 
S

second_existenc

Guest
Not working

Ok so i tried your idea because it looked to be the most straight forward.

Smart said:
in the after update of 2nd box write this code
nameof3rdbox = namof1stbox + nameof2ndbox

You might want validation before performing the addition
ie making sur a value is in 1stbox and 2nd box

Hope this helps

Ok, I tried this and I get the message. Microsoft Office can't find the Macro 'text10 = (text8 + text6).'

Any more help.

P.s Im not sure what you mean by
"You might want validation before performing the addition
ie making sur a value is in 1stbox and 2nd box"

Thanks
 

ScottGem

Registered User.
Local time
Today, 14:38
Joined
Jun 20, 2005
Messages
1,119
you need to enter that using the code builder, not jusst type it in the box.
 

Users who are viewing this thread

Top Bottom