Nicolas
Nicolas

Reputation: 2376

Numpad point gets inserted as a comma in my Access textbox

This seems to be a language issue which has been addressed multiple times. However, all examples I have read give the solution to change the language settings / decimal separator in my region settings.

The problem is that I can't do this. I am using the local language setting with a decimal separator because in our county (Netherlands) decimals get separated with a comma, however if I change the Region --> Additional Settings --> numbers Decimal symbol to a point (also for currency) then our values get, obviously, a point decimal separator instead of a comma.

Though, we also use a point in a lot of our article numbers and to do this fast we use the point on the numpad. With the current region settings however, access changes the point on the numpad to a comma as well.. I already tried to catch the Ascii key on the keydown event of a text box and change it from comma to point, BUT for some reason the Ascii keycode on the numpad for point is the same Keycode as the point on the regular keyboard (46) but a comma is still inserted. I did I could simple change the Keyascii with the point ascii but this won't work (since ascii already thinks it is a point).

Any idea why this happens, and more important, how I can fix it without changing my region settings? So the perfect scenario is that the point on the numpad is just that, a point.

Upvotes: 0

Views: 890

Answers (3)

Erik A
Erik A

Reputation: 32682

A bad practice you can also use, and which offers a solution to this and more localization problems: change the localization settings while access is running.

Create a form, and an AutoExec macro that opens the form in hidden mode, then add the following code to the form:

Private Sub Form_Open(Cancel As Integer)
    Dim wsh As Object
    Set wsh = CreateObject("WScript.Shell")
    wsh.RegWrite "HKCU\Control Panel\International\sDecimal", "."
End Sub

Public Sub Form_Close()
    Dim wsh As Object
    Set wsh = CreateObject("WScript.Shell")
    wsh.RegWrite "HKCU\Control Panel\International\sDecimal", ","
End Sub

If your only problem is specific textboxes and the numpad, this solution is overkill and has serious disadvantages (like it also changes the locale settings in other programs as long as Access is running). But if you really want to change locale settings only for Access this can help.

Upvotes: 0

Andre
Andre

Reputation: 27644

You can distinguish them in the KeyDown event, not in KeyPress. Every key has a separate KeyCode, unlike the KeyAscii.

With this code:

Private Sub txtID_KeyDown(KeyCode As Integer, Shift As Integer)
    Debug.Print "KeyCode: " & KeyCode
End Sub

Private Sub txtID_KeyPress(KeyAscii As Integer)
    Debug.Print "KeyAscii: " & KeyAscii
End Sub

I get on a German keyboard:

Regular dot .
KeyCode: 190
KeyAscii: 46

Regular comma ,
KeyCode: 188
KeyAscii: 44

Numpad comma ,
KeyCode: 110
KeyAscii: 44

Edit

And with

Private Sub txtID_KeyDown(KeyCode As Integer, Shift As Integer)

    ' Change Numpad comma into dot
    If KeyCode = 110 Then KeyCode = 190

End Sub

I can type a dot with the Numpad comma.

Upvotes: 1

Gustav
Gustav

Reputation: 55906

You can convert from your localised number format to a string with a dot:

CommaValue = "34,5"
TextInput = Str(CDbl(CommaValue))

' TextInput -> "34.5"

Upvotes: 0

Related Questions