how to calculate value in textbox

luzz

Registered User.
Local time
Yesterday, 20:08
Joined
Aug 23, 2017
Messages
346
Hi all, I would like to ask if it is possible to calculate this type of value :
20+ 2+ 2 in textbox?

Like for now, I have two textbox .
Textbox A has value : 20 + 2 +2
Then textbox box b has value of 20 , then i want to add textbox A value to textbox b.
This means that textbox b = 44, [20 + 20 + 2 + 2]
 
Yes, although it is highly not advised - Access is not Excel.
If they are distinct values they should be stored separately.

What have you tried? Research the Eval() method.
 
use Eval() function:

textB=Eval(textA)
 
Hi all, I would like to ask if it is possible to calculate this type of value :
20+ 2+ 2 in textbox?

Like for now, I have two textbox .
Textbox A has value : 20 + 2 +2
Then textbox box b has value of 20 , then i want to add textbox A value to textbox b.
This means that textbox b = 44, [20 + 20 + 2 + 2]

You can't have two values in textbox b. You'd have to create an event (Button click ?) that modifies textbox b, like
Code:
textboxB = textboxB + Eval(textboxA)

Best,
Jiri
 
Note further that if text box B is BOUND, then you cannot do this without altering the underlying record because binding generally limits what you can do with the contents of a control.
 
You can't have two values in textbox b. You'd have to create an event (Button click ?) that modifies textbox b, like
Code:
textboxB = textboxB + Eval(textboxA)

Best,
Jiri

Yes, i do have a button to click and calculate textbox B
 
Hi all, I tried the method you guys said, but i am still getting error.
Below is my code:
Code:
If Me.txtLbs <= 130 Then
Me.txtGrossweight = (Me.txtNettweight + 20) + Eval(Me.txtBuyerRequirement)

I have also attached a image of my form and the error
 

Attachments

  • Untitled.png
    Untitled.png
    31.7 KB · Views: 94
That is a datatype error for storing data in a field.

This means that the txtGrossweight control is BOUND and one or the other of the other controls is of a different data type (or the expression is being forced to a different data type) than the target field (that is associated with the control).
 
That is a datatype error for storing data in a field.

This means that the txtGrossweight control is BOUND and one or the other of the other controls is of a different data type (or the expression is being forced to a different data type) than the target field (that is associated with the control).

Nope, txtGrossweight is not bound as i will need to use button to display the value
 
I can't help feeling this would be better achieved in the underlying forms query.
 
I can't help feeling this would be better achieved in the underlying forms query.

The problem now is that i am not able to key in "+" sign in my textbox
 
I don't understand why you would want this functionality. You can add 2 or 10 control boxes up in either code or a query, why try and build a calculator into access?
 
Nope, txtGrossweight is not bound as i will need to use button to display the value

A totally unbound text box will not do this unless you have set constraints on the format of the box. That error is a data type mismatch where the computation produces something with a data type that is inconsistent with the type of the destination.
 
I don't understand why you would want this functionality. You can add 2 or 10 control boxes up in either code or a query, why try and build a calculator into access?

As this is one of the requirement given by the user. Hence, i have to try to get it done. Well, you said this can be done in either code or query, with that can the user still key in the the value they want in the textbox on the form?
 
A totally unbound text box will not do this unless you have set constraints on the format of the box. That error is a data type mismatch where the computation produces something with a data type that is inconsistent with the type of the destination.

does that mean i will need to change the data type?
 
does that mean i will need to change the data type?

Somewhere along the line, yes. You can probably typecast or format the expression before trying to store it. If you are not familiar with typecasting, it really is just applying one of several possible functions to change an element from one data type to another. Like using CDbl(x) to make X appear in DOUBLE format. Or CStr() to convert something to a string. There are many other such functions as well.

I'm betting you need a string in your text box, so CStr() is probably what you will need. But I could be wrong. Try a few things and see what Access likes. It is, after all, the sole arbiter of syntax.
 
As this is one of the requirement given by the user. Hence, i have to try to get it done. Well, you said this can be done in either code or query, with that can the user still key in the the value they want in the textbox on the form?

My comment is that if these are values are already somewhere in the database then you can do the calculations behind the scenes.

If they aren't the they probably should be stored so the end value can be calculated. That is how a database works. Data in - Manipulated Data out.

https://www.youtube.com/watch?v=l5vsqWPdiLE
 

Users who are viewing this thread

Back
Top Bottom