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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I force the users keyboard to uppercase? 2

Status
Not open for further replies.

steve728

Programmer
Mar 16, 2003
536
US
I know you can use the ">" symbol to force the txtbox entry to upper case but what is the VBA code syntax to force the keyboard to uppercase? I'm needing this info for MS Access 2000.

Thanks!

Steve
 
I don't know if it is ethical to change the keyboard setting. I would be very annoyed as a user if the program later required lower case and I continually started typing in upper case as a result. The usual method is to accept any input and change it using Ucase() afterwards. However, for the sake of the exercise, this code will do the job (can check by seeing the light on the keyboard come on).

'---------------------------------------------------
Private Declare Function GetKeyState Lib "user32" _
(ByVal nVirtKey As Long) As Long
'-
Private Declare Sub keybd_event Lib "user32" _
(ByVal bVk As Byte, ByVal bScan As Byte, _
ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
'-
Private Declare Function MapVirtualKey Lib "user32" _
Alias "MapVirtualKeyA" _
(ByVal wCode As Long, ByVal wMapType As Long) As Long
'--------------------------------------------------------
Private Sub CAPS_LOCK_ON()
'- if caps lock off then 'press' key
If GetKeyState(&H14) = 0 Then
Call keybd_event(&H14, _
MapVirtualKey(&H14, 0), KEYEVENTF_EXTENDEDKEY Or 0, 0)
Call keybd_event(&H14, _
MapVirtualKey(&H14, 0), KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0)
End If
End Sub
'------------------------------------------------------


Regards
BrianB
** Let us know if you get something that works !
================================
 
I agree with BrianB that Ucase() would be better after the input.

As an alternative you could use this to turn Caps Lock on :-

SendKeys "{CAPSLOCK}", True

But ethically its not good.

As you said steve, forcing a textbox entry to uppercase is easy through input masks.
 
As BrianB and TopJack said, I wouldn't change a users Caplocks. If the input is in a textbox, you could use the textbox change event to force the input to upper case.

Code:
Private Sub TextBox1_Change()
   TextBox1.Text = UCase(TextBox1.Text)
End Sub
 
Thank you so much for all your quick advise! I agree
with you regarding the ethical part. Perhaps I'll tell my friend to not be so lazy and control the caps himself. I can provide the > and UCase() instead.

Thanks Cyber Buddies!

Steve
 
I found this one-liner extremely usefull! it forces upper case as you type when adding it to the 'On Key-Press' event of any text box.

KeyAscii = Asc(UCase(Chr(KeyAscii)))

PS I've used it in VB6 and Access 97.
 
It sounds perfect! I didn't any luck with the
SendKeys "{CAPSLOCK}", True
I haven't tried the 1st, lengthy coding one. I'm sure
it will work but it's length is discouraging enough
to tell my friend to "just hit the Caps key LAZY Dude!"

Thanks to all of you again!
 
You could always try supergluing the bloke's shift key down.

Always adhere to the "keep it simple" philosophy. :)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top