Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Prevent using , when . is defined as decimal seperator on a form 1

Status
Not open for further replies.

WillemdeNie

Programmer
Sep 15, 2003
44
NL
Input field requires to enter a decimal numer.
User should enter for example 2.30 but enters 2,30

2,30 is seen by ACCESS as 230 because , is not the decimal seperator but as the thousand seperator.
Testing on numeric does not work
On a other computer with other language settings it could be different.
 
Could put code in the Key Press event of the textbox:

Select Case KeyAscii
' Allow only 0 thru 9, period, and backspace, cancel everything else.
Case 8, 46, 48 To 57
' Do nothing.
Case Else
' Cancel input.
KeyAscii = 0
End Select
 
If you change the input field to text, you can apply an input mask. You can then convert the data to numeric whenever you need to use it in calculations.

 
Thanks for replying; it works almost! But I want to replace . and the , by the decimal seperator on the numeric keyboard.
If I use that key it always gives as a 110 indepent whether Numlock is activated. So this does not work.

Private Sub Tekst0_KeyPress(KeyAscii As Integer)
MsgBox (KeyAscii) ' for test

If KeyAscii = 190 Or KeyAscii = 188 Then
KeyAscii = 110
End If
MsgBox (KeyAscii) ' for test

End Sub
 
Hmmm...Not able to duplicate what you are seeing. My numeric keypad decimal seperator (.) is KeyAscii 46, same as the keyboard period, and my comma is 44. If I put:

If KeyAscii = 44 Then
KeyAscii = 46
End If

then comma is changed to a period.

 
That is what I also would expect. The only difference is that my country configiguration is Dutch so the decimal seperator on the num keypad (.) gives a comma! And that is OK. Now I want a normal . also changed in a , (for the situation user is not using the num keypad and by mistake uses a . instead of a ,

Appriciate another advice if you have any.

Anyway thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top