Use Keydown to change character displayed

M

mieds

Hi,

I am trying to use the following sub to change a period to a colin
when entered in a textbox. This code only produces a semi-colin, can
someone please point out what I am doing wrong or provide a different
way to accomplish this.

Thanks

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

Select Case KeyCode
Case 190
KeyCode = 186
Case Else
'Debug.Print KeyCode, Shift
End Select

End Sub
 
L

Linq Adams via AccessMonster.com

The problem is that only one Keycode is assigned per key. Both colon and
semicolon return a Keycode of 186, and since the semi-colon is the character
produced by hitting the key (a colon requires hitting <Shift> + the key)
that's what your code produces. I know how to trap a <Shift> + key
combination, but I don't know how to assign a <Shift> + key combination. But
this code will do the same thing, using standard ASCII values:

Private Sub Text0_Change()
If Right(Text0.Text, 1) = Chr(46) Then
Text0.Text = Left(Text0.Text, Len(Text0.Text) - 1) & Chr(58)
Text0.SelStart = Len(Text0.Text)
End If
End Sub
 
M

mieds

Thanks that worked great. I tried to assign a shift, but could not
figure it out either.
 

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

Similar Threads


Top