Concatenates two numbers instead of adding them in a text box, using plus sign (+) (1 Viewer)

pacctono

Member
Local time
Today, 16:21
Joined
Jun 13, 2022
Messages
64
Hello!

I created a control text box that calculates the sum of two numeric columns that comes from a query. (the two numeric columns are in text box controls, too). Something like '=[monAhorroAporte]+[monAhorroPersonal]'. Instead I am getting the concatenation of the two numbers. 12,79+27,55=12,7927,55. Looks like access is using plus sign (+) to concatenate as ampersand (&) and trying the two numeric fields as string.

Can any one tell me if I can have a text box control to get aritmethic expression and how to do it?

NOTE: I am using spanish language

campoMalCalculados.png
 

plog

Banishment Pending
Local time
Today, 15:21
Joined
May 11, 2011
Messages
11,638
I'd wrap the individual values in a Val() and then add them:

 

pacctono

Member
Local time
Today, 16:21
Joined
Jun 13, 2022
Messages
64
I'd wrap the individual values in a Val() and then add them:

I tried that, but as the two numbers are taken as string (12,79 and 27,55), access takes only the integer part. the problem is the that it is expecting a decimal point and in spanish we use comma.
 

plog

Banishment Pending
Local time
Today, 15:21
Joined
May 11, 2011
Messages
11,638
Why are they as string? You need to fix the root issue. And don't blame a language, every nation and culture uses numbers--the same set in fact.

In your query you need to remove any formatting if you want these numbers to be numbers. If the issue is that you are storing them as text in a table, you need to fix that and change the field to the appropriate numeric type. Then in the form you can do the math you want and you can also format the control so that it diisplays those numbers in the format you want.
 

pacctono

Member
Local time
Today, 16:21
Joined
Jun 13, 2022
Messages
64
Why are they as string? You need to fix the root issue. And don't blame a language, every nation and culture uses numbers--the same set in fact.

In your query you need to remove any formatting if you want these numbers to be numbers. If the issue is that you are storing them as text in a table, you need to fix that and change the field to the appropriate numeric type. Then in the form you can do the math you want and you can also format the control so that it diisplays those numbers in the format you want.
The values are numeric (they come from a SUM) and I formatted them as standard with two decimals. Spanish is my language and I like it but I do not understand why access translate words like 'True' in a boolean column/variable.

For example, I did an <txtSql = "UPDATE table SET bo_aps = " & booAps> where bo_aps is a table column of type boolean and booAps is a vba variable of type boolean. I got an error because 'txtSql' was "UPDATE table SET bo_aps = Verdadero" and did not understand the 'Verdadero' value. So I had to create a function to return the string "True" or "False".
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 16:21
Joined
May 21, 2018
Messages
8,525
The values are numeric (they come from a SUM) and I formatted them as standard with two decimals.
It is unclear how you formatted the number, but a format function returns STRING.
Wrap the sum in a CCUR() function instead to convert the value to a currency.
Bottom line is those inputs are STRINGS. Somehow you converted them into a string. Has nothing to do with the regional settings.
 

pacctono

Member
Local time
Today, 16:21
Joined
Jun 13, 2022
Messages
64
It is unclear how you formatted the number, but a format function returns STRING.
Wrap the sum in a CCUR() function instead to convert the value to a currency.
Bottom line is those inputs are STRINGS. Somehow you converted them into a string. Has nothing to do with the regional settings.
Sorry! I did not explain myself. I am not using the format function. when I talk to format, I am talking to the properties of the control text box that I choosed 'standar' with 2 decimals as always do with numbers.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 04:21
Joined
May 7, 2009
Messages
19,229
you can create a function in a Module to convert your textbox to Real number:
Code:
Public Function fnVal(ByVal var As Variant) As Variant
    Dim a As Integer
    fnVal = var
    If IsNull(var) Then
        Exit Function
    End If
    var = Trim$(var & "")
    a = Len(var) - InStrRev(var, ",")
    var = Replace$(var, ",", "")
    If a = 2 Then
        var = Left$(var, Len(var) - 2) & "." & Right$(var, 2)
    End If
    fnVal = Val(var)
End Function

=fnVal([Textbox1]) + fnVal([Textbox])
 

Users who are viewing this thread

Top Bottom