Reversing Shift Key Action (1 Viewer)

cosmarchy

Registered User.
Local time
Today, 05:52
Joined
Jan 19, 2010
Messages
116
Hi,

In a particular textbox on a form, I need to have whatever is typed converted to uppercase with some exceptions.

So I need a way of converting the keypresses as I cannot just use a blanket convert to uppercase as there are a few which need to remain lowercase.

My thinking is that I would use the textbox KeyPress event and convert any ASCIIKeys between 'a' and 'z' to 'A' and 'Z' respectively. The issue is that I need, on occasion to use the shift key to essentially convert back to lowercase regardless of caps lock.
So, in brief I need to ignore caps lock and ensure that any lower case alphabetic character is converted to uppercase until the shift key is held down in which all alphabetic characters are lowercase.
The KeyPress function does not allow for the detection of the shift key so my question is how can I achieve this?

Has anyone had to do this before?

Thanks
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 20:52
Joined
May 7, 2009
Messages
19,245
on a particular textbox on your form,
put these codes to its corresponding
event.

Code:
Option Compare Database
Option Explicit
Dim bolShifted As Boolean
Private Sub textBoxName_KeyDown(KeyCode As Integer, Shift As Integer)
    ' 1 = Shift Key
    ' 2 = Ctrl Key
    If Shift = 1 Then bolShifted = (Not bolShifted)
End Sub

Private Sub textBoxName_KeyPress(KeyAscii As Integer)
    If Not bolShifted Then _
        KeyAscii = Asc(UCase(Chr(KeyAscii)))
End Sub
 

cosmarchy

Registered User.
Local time
Today, 05:52
Joined
Jan 19, 2010
Messages
116
on a particular textbox on your form,
put these codes to its corresponding
event.

Code:
Option Compare Database
Option Explicit
Dim bolShifted As Boolean
Private Sub textBoxName_KeyDown(KeyCode As Integer, Shift As Integer)
    ' 1 = Shift Key
    ' 2 = Ctrl Key
    If Shift = 1 Then bolShifted = (Not bolShifted)
End Sub

Private Sub textBoxName_KeyPress(KeyAscii As Integer)
    If Not bolShifted Then _
        KeyAscii = Asc(UCase(Chr(KeyAscii)))
End Sub

Many thanks for this :)
 

Users who are viewing this thread

Top Bottom