#AskMe

VBA Converting Khmer Numeric to Ascii for TextBox Number

Have you ever found this when you type Number using Khmer Unicode Keyboard ?

The error message:

The value you entered isn’t valid for this field.

For example, you may have entered text in a numeric field or a number that is larger than the FieldSize settings permits.

MS Access 2010

Above error is simple for us as our characters are in Unicode and of course, if we check Keycode, it’s the same from number 0 to 9 but when we check ASCII code on each typing of the numeric, it’s not the same.

I solved it in a very simple way by converting the unicode ascii to numeric ascii

NumberKhmer Unicode Number ASCII
Number in ASCII
0611248
1611349
2611450
3611551
4611652
5611753
6611854
7611955
8612056
9612157

By then we can do it on event “KeyPress” to detect the ASCII code of the typing:

They when you type the number will transform itself to Latin Numeric, prevent you error with the VBA form as above. And you can find the source code to copy as following:

<code>Select Case KeyAscii
Case 6112 '0
	KeyAscii = 48
Case 6113
	KeyAscii = 49
Case 6114
	KeyAscii = 50
Case 6115
	KeyAscii = 51
Case 6116
	KeyAscii = 52
Case 6117
	KeyAscii = 53
Case 6118
	KeyAscii = 54
Case 6119
	KeyAscii = 55
Case 6120
	KeyAscii = 56
Case 6121 '9
	KeyAscii = 57
End Select</code>