how to convert commas in dots while writing

M

Marco

Hi. I would like transform/convert a comma into dot.

I think that something as Keydown = , then . somethign like that.

Is it possible?


Regards,
Marco
 
L

Linq Adams via AccessMonster.com

For a given control

Private Sub YourControlName_Change()

If Right(YourControlName.Text, 1) = Chr(44) Then
YourControlName.Text = Left(YourControlName.Text, Len(YourControlName.Text) -
1) & Chr(46)

End If
End Sub

The lines If Right...Chr(46) all need to be on a single line in your actual
code.

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000/2003

Message posted via AccessMonster.com
 
L

Linq Adams via AccessMonster.com

Sorry, scratch the comment about

"The lines If Right...Chr(46) all need to be on a single line in your actual
code."

It should read:

YourControlName.Text = Left(YourControlName.Text, Len(YourControlName.Text) -
1) & Chr(46)

needs to be on one line.
 
M

Marco

Hi.

It works but there's just a little problem. When I press a comma then it
changes to a dot but then the mause coursor goes to the start of the text. It
goes to the left.

How can we change this?

Thanks,
Marco
 
L

Linq Adams via AccessMonster.com

No idea! Just went back to the text db I used and it doesn't do this for me.
And I can't even imagine what would cause it vis a vis other code you might
have!

I was just getting ready to repost with another solution, which you might try:


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

If KeyCode = 188 Then KeyCode = 190

End Sub

Try this and see if you have the same problem.
 
A

AccessVandal via AccessMonster.com

Have you tried using the textbox keypress event?

If KeyAscii = 46 Then KeyAscii = 44
 
M

Marco

Hi. it works.

How can I control if it comes from numeric keyboard. the one from the right
side of the keyboard?

I cannot change my regional settings. :( can I control the numeric keyboard?

Regards,
Marco
 
L

Linq Adams via AccessMonster.com

How can I control if it comes from numeric keyboard. the one from the right
side of the keyboard?

How can you control what? Your original question was how to replace commas
with periods/decimal points. I've never seen a "comma" key on a numeric
keyboard! Are you saying yours has one?
 
M

Marco

Yes, of course.

In numeric keyboard or keypad as also we can call it has a dot or a comma it
depends on your regional settings. I'm talking about the key in right of
zero.

Because I'm from Portugal, and in Portugal the decimal simbol is a comma,
when I press that key it appears me a comma not a dot. Because is the comma
the is defined in the regional settings.

Cheers,
Marco
 
A

AccessVandal via AccessMonster.com

The keypress event will not work on the keypad. Use the keydown event as Linq
Adams suggested.

First you need to find out the KeyCode number for the keypad and the comma.
Use an MsgBox or A Debug.Print like,

MsgBox “KeyCode = “ & KeyCode
Or
Debug.Print KeyCode

The US keyboard, the keycode for comma is “188â€, the period is “190†and the
keypad decimal is “110â€. It should the same for Portugal settings.

Private Sub YourTextBoxName_KeyDown(KeyCode As Integer, Shift As Integer)
Debug.Print KeyCode
MsgBox “KeyCode was “ & KeyCode
If KeyCode = 110 Then KeyCode = 188
MsgBox “KeyCode now is “ & KeyCode
End Sub
 
A

AccessVandal via AccessMonster.com

AccessVandal said:
If KeyCode = 110 Then KeyCode = 188 'change from decimal to comma on the keypad

Note:

Change it to "If KeyCode = 188 Then KeyCode = 110" or to "190" if you want
the comma as decimal.
 
M

Marco

Hello.

I tried but it still not working. What I need is to change the comma for a
dot.

This code from Adam qorks, but puts the mouse cursor at the beginning of the
field:

If Right(YourControlName.Text, 1) = Chr(44) Then
YourControlName.Text = Left(YourControlName.Text, Len(YourControlName.Text) -
1) & Chr(46)

End If

Means theat the user was always typing in the wrong place.

What else can I do?

PLEASE HELP. :(

Regards,
Marco
 
A

AccessVandal via AccessMonster.com

I think you’re confused somewhere. Did you use the TextBox KeyDown Event as
suggested?

Why use the Right(), Left() and Len() Function? These will cause the cursor
to move away as the user continues to key in data, thereby, creating a
problem.

Please refer to my previous post about finding the keycode.

Private Sub YourTextBoxName_KeyDown(KeyCode As Integer, Shift As Integer)
’US keyboard 190 = Dot or 110 = Dot and 188 = comma
MsgBox “KeyCode was “ & KeyCode
If KeyCode = 110 Then KeyCode = 190
MsgBox “KeyCode now is “ & KeyCode

End Sub

“YourTextBoxName†or “YourControlName†refers to the name of the control. You
must rename it. Do not copy the code if you don’t understand it.

If you named your control to say… “txtActualCostâ€, then replace this name to

“Private Sub txtActualCost_KeyDown(KeyCode As Integer, Shift As Integer)â€

“Right(txtActualCost.Text, 1) = Chr(44) Thenâ€

Got it?
 
M

Marco Silva

Hello.

I'm sorry I tried what you told me but I had another code on keypress so
this wasn't working.

the message box returns me:
Keycode was 110 and now is 110 strange isn't it?

Is impossible to solve this?

I'm so dead.


Thanks,
Marco
 
A

AccessVandal via AccessMonster.com

Make sure that you have remove or disable the key press event.

What is the actual code of your keydown event is it possible to post your
code here?

I have tested with the region setting to Portugal. The keypad keycode is 110
(as a comma for Portugal). Make sure that your code is like

If KeyCode = 110 Then KeyCode = 190 ‘convert Portugal setting to decimal

Cause 110 is a comma in Portugal setting not a dot as in the US setting, you
need to refer to the dot on the keyboard, which is keycode 190 for the
decimal.

It works on my end.
 
M

Marco

thanks bro. it's working

THANK YOU.

:)


AccessVandal via AccessMonster.com said:
Make sure that you have remove or disable the key press event.

What is the actual code of your keydown event is it possible to post your
code here?

I have tested with the region setting to Portugal. The keypad keycode is 110
(as a comma for Portugal). Make sure that your code is like

If KeyCode = 110 Then KeyCode = 190 ‘convert Portugal setting to decimal

Cause 110 is a comma in Portugal setting not a dot as in the US setting, you
need to refer to the dot on the keyboard, which is keycode 190 for the
decimal.

It works on my end.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top