Change dots into commas as decimal separator (1 Viewer)

cpampas

Registered User.
Local time
Today, 09:10
Joined
Jul 23, 2012
Messages
181
Hi,
I cant figure out how to change dots into comas to separate the decimal part of a number

Code:
If KeyCode = 190 Then KeyCode = 110

the previous code on the keydown event works when entering numbers separated with commas, but not in case I paste a number
When I copy 55.55, into my form control, and after pasting i get 5555,00 and not 55,55 as desired

Also, the replace function in the afterupdate event wont work, because once that event happens the number is already assumed 5555,00
Any thoughts on how to get the correct number entered when using copy/paste
Thanks
 

CJ_London

Super Moderator
Staff member
Local time
Today, 17:10
Joined
Feb 19, 2013
Messages
14,685
need more information.

Is any formatting applied?
is an input mask used?
If the control is bound, what is the underlying datatype?
what is your windows setting for displaying numbers?
is this the same setting in access?
 

sonic8

AWF VIP
Local time
Today, 18:10
Joined
Oct 27, 2015
Messages
610
When I copy 55.55, into my form control, and after pasting i get 5555,00 and not 55,55 as desired

Also, the replace function in the afterupdate event wont work, because once that event happens the number is already assumed 5555,00
The Change event of the text box fires before the text has been parsed to a number.
 

cpampas

Registered User.
Local time
Today, 09:10
Joined
Jul 23, 2012
Messages
181
The Change event of the text box fires before the text has been parsed to a number.

I tried the chang event wich is triggered when I paste the number 55.55, but I on that event I cant access the number as it is not available yet to manipulate with the replace function

CJ_London,
there is no formating applied
no input mask
the control is bound to a datatype number/double

the decimal separator : coma
digit grouping : dot

example : 6.789,12

Where can I check the settings for numbers in Access ?
 
Last edited:

CJ_London

Super Moderator
Staff member
Local time
Today, 17:10
Joined
Feb 19, 2013
Messages
14,685
Where can I check the settings for numbers in Access ?
Pretty sure it is dependent on the language settings File>Options>Language

I tried the chang event wich is triggered when I paste the number 55.55, but I on that event I cant access the number as it is not available yet to manipulate with the replace function

you reference the text property - simple example (in this case converting a , to a .

Private Sub Text2_Change()

Text2.Text = Replace(Text2.Text, ",", ".")

End Sub

this is what I had when copying the value in text0 and pasting to text2

image_2022-05-21_224712921.png


you have a bit more work to do if you have a value 123.456,78

So instead I suggest you use the key up event instead since several changes are required which will create a chain reaction within the change event

Code:
Private Sub Text2_KeyUp(KeyCode As Integer, Shift As Integer)
Dim s() As String
'123.456,78
    Debug.Print Text2.Text
    s = Split(Text2.Text, ",")
    Debug.Print s(0)
    Debug.Print s(1)
    Text2.Text = Replace(s(0), ".", ",") & "." & s(1)
End Sub
to produce this result
image_2022-05-21_230837086.png


and don't use any formatting - but you can align text to right

Note the above code is an example - it assume you are using ctrl-V to paste (not mouse right click) and consequently needs modifying for other sorts of values (so if some numbers are copied as 123,456.78 the code will fail as it will if you try to edit the value). You will need to put your own protections around it
 

cpampas

Registered User.
Local time
Today, 09:10
Joined
Jul 23, 2012
Messages
181
That works nicely. Many thanks for your help
 

Eugene-LS

Registered User.
Local time
Today, 19:10
Joined
Dec 7, 2018
Messages
354

@cpampas

Any Null value will return error - so better use Nz() function:
Me.txtTextField = Replace(Nz(Me.txtNumericField, 0), ",", ".")
 

Users who are viewing this thread

Top Bottom