Adding 2 controls to get a total

R

Ryis

hello,,

I am trying to add 2 controls together to get a total

R1=1
R2=2
Total=3

I am using the following =Nz([R1],0)+Nz([R2],0), but the total control keeps
returning "12"

can anybody help me...i am sure it is something simple...but can't get me
head around it

thanks in advance

Ryan
 
R

Ryis

Control Names are R1 & R2...the control to add them up is RTOTAL. These
controls are only on the form and are used to calculate a exam total.

Ryan
 
D

Dalt

you should be able to do something like RTotal.value = R1.value + R2.value

Assuming of course the controls are text boxes, but it's not clear from your
first post.
 
R

Ryis

Would I put this in the contol of RTOTAL?? I tried R1.Value+R2.Value but i
still just get 12 not 3..all the fields are text, should they be number?

Ryan
 
J

John W. Vinson

Would I put this in the contol of RTOTAL?? I tried R1.Value+R2.Value but i
still just get 12 not 3..all the fields are text, should they be number?

If you want to do arithmatic on the fields, then yes, they should be numbers.
What is "3" + "ABC" equal to!?

The + operator adds numbers, but it concatenates text strings; i.e. "1" + "2"
is quite correctly being returned as "12", just as "A" + "B" will return "AB".
 
R

Ryis

Hi Dalt,

It worked for a brief then gone again...i have 30 fields that are controlled
by a iff statement which returns either a 1 or a 0, i need the total to
return the total of all the ones and zeros...just cant get it to work...it
returns the following 1110001111....etc

the fields are numericall order like so [RQ1],[RQ2]----->[RQ30], the total
is labelled [R TOTAL]
 
R

Ryis

Hi John,

this is what i have in the control of R TOTAL =[RQ1]+[RQ2]

RQ1,RQ2 are field names
Values:
RQ1=1
RQ2=2

the response i get is 12 not 3...what am i doing wrong
 
D

Dalt

What you could do is declare some variables as integers and set the variable
to the value of the text field, this would force the code to treat the text
as a number instead of text. I'm not sure of another way but this should
definately work.

Dim Num1 as Integer
Dim Num2 as Integer

Num1 = Control1.Value
Num2 = Control2.Value

Total = Num1 + Num2


Ryis said:
Hi Dalt,

It worked for a brief then gone again...i have 30 fields that are controlled
by a iff statement which returns either a 1 or a 0, i need the total to
return the total of all the ones and zeros...just cant get it to work...it
returns the following 1110001111....etc

the fields are numericall order like so [RQ1],[RQ2]----->[RQ30], the total
is labelled [R TOTAL]

Dalt said:
you should be able to do something like RTotal.value = R1.value + R2.value

Assuming of course the controls are text boxes, but it's not clear from your
first post.
 
T

tkelley via AccessMonster.com

Yes.

or Cint([RQ1) + Cint([RQ2]) + ...

However, if there is any chance of there being a non-numeric value, you'll
need to account for that. But it doesn't sound like that is the case for you.

What you could do is declare some variables as integers and set the variable
to the value of the text field, this would force the code to treat the text
as a number instead of text. I'm not sure of another way but this should
definately work.

Dim Num1 as Integer
Dim Num2 as Integer

Num1 = Control1.Value
Num2 = Control2.Value

Total = Num1 + Num2
[quoted text clipped - 17 lines]
 
B

Beetle

Did you change the data type to Number instead of Text?

BTW - You table design of [RQ1], [RQ2], .............[RQ30] is flawed. When
you need to add [RQ31], you are going to have to redesign the table,
as well as *everything else* (queries, forms, reports) that is based on it.
--
_________

Sean Bailey


Ryis said:
Hi John,

this is what i have in the control of R TOTAL =[RQ1]+[RQ2]

RQ1,RQ2 are field names
Values:
RQ1=1
RQ2=2

the response i get is 12 not 3...what am i doing wrong

John W. Vinson said:
If you want to do arithmatic on the fields, then yes, they should be numbers.
What is "3" + "ABC" equal to!?

The + operator adds numbers, but it concatenates text strings; i.e. "1" + "2"
is quite correctly being returned as "12", just as "A" + "B" will return "AB".
 
J

John W. Vinson

Hi John,

this is what i have in the control of R TOTAL =[RQ1]+[RQ2]

RQ1,RQ2 are field names
Values:
RQ1=1
RQ2=2

the response i get is 12 not 3...what am i doing wrong

What you are doing wrong is just what I *TOLD* you you were doing wrong:
storing arithmatic data as Text.

If you change the datatypes of RQ1 and RQ2 in your Table from Text to Number
(Long Integer) then 1 + 2 will equal 3.

Or, you can use an expression

=Value([RQ1]) + Value([RQ2])

to convert the text string "1" into a number 1, and then add that number.


I will say that if you have table fields named RQ1 and RQ2 containing the same
kind of information (likely, since you're trying to add them) that your table
design *is wrong*. Tables are not spreadsheets! See some of the tutorials at:

Jeff Conrad's resources page:
http://www.accessmvp.com/JConrad/accessjunkie/resources.html

The Access Web resources page:
http://www.mvps.org/access/resources/index.html

A free tutorial written by Crystal (MS Access MVP):
http://allenbrowne.com/casu-22.html

MVP Allen Browne's tutorials:
http://allenbrowne.com/links.html#Tutorials
 
D

Derek

Your total control thinks that you are adding text fields together
Re-format fields or better:

If your controls are on a form and form is based on a table create a query
using the table then create an extra column in query by typing
Total:([R1]+[R2]) in any blank column heading. This has the advantage of
calculating automaticaly when inputing data. Use the query as record source
for form

R1 must be the Controls Field Name or replace R1 with Field Name
R2 must be the Controls Field Name or replace R2 with Field Name

Control "Total" record source is Total from Query

Good luck


tkelley via AccessMonster.com said:
Yes.

or Cint([RQ1) + Cint([RQ2]) + ...

However, if there is any chance of there being a non-numeric value, you'll
need to account for that. But it doesn't sound like that is the case for
you.

What you could do is declare some variables as integers and set the
variable
to the value of the text field, this would force the code to treat the
text
as a number instead of text. I'm not sure of another way but this should
definately work.

Dim Num1 as Integer
Dim Num2 as Integer

Num1 = Control1.Value
Num2 = Control2.Value

Total = Num1 + Num2
[quoted text clipped - 17 lines]
Can you give more information? What are the control names?
 
R

Ryis

These fields are one time uses which pull data from the table and then
calculate a percentage for a exam result....as soon as the form closes they
are gone again. I think I will have to create a answer key table for all my
exam answers. Thanks for your time John.

Ryan

John W. Vinson said:
Hi John,

this is what i have in the control of R TOTAL =[RQ1]+[RQ2]

RQ1,RQ2 are field names
Values:
RQ1=1
RQ2=2

the response i get is 12 not 3...what am i doing wrong

What you are doing wrong is just what I *TOLD* you you were doing wrong:
storing arithmatic data as Text.

If you change the datatypes of RQ1 and RQ2 in your Table from Text to Number
(Long Integer) then 1 + 2 will equal 3.

Or, you can use an expression

=Value([RQ1]) + Value([RQ2])

to convert the text string "1" into a number 1, and then add that number.


I will say that if you have table fields named RQ1 and RQ2 containing the same
kind of information (likely, since you're trying to add them) that your table
design *is wrong*. Tables are not spreadsheets! See some of the tutorials at:

Jeff Conrad's resources page:
http://www.accessmvp.com/JConrad/accessjunkie/resources.html

The Access Web resources page:
http://www.mvps.org/access/resources/index.html

A free tutorial written by Crystal (MS Access MVP):
http://allenbrowne.com/casu-22.html

MVP Allen Browne's tutorials:
http://allenbrowne.com/links.html#Tutorials
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top