PDA

View Full Version : Solved: Upper Case to Proper Case



clhare
09-17-2007, 06:45 AM
I have been asked to update a userform to make sure that the text entered is not all caps. Is there any easy way to do this or do I have to do an "If uppercase, switch to proper case" thing on each textbox in the userform?

SOS
09-17-2007, 07:23 AM
clhare,

Remember this thread

http://www.vbaexpress.com/forum/showthread.php?t=14520

It started out as a request from me about StrConv all textboxes and quickly moved on to be quite a long thread indeed.

Anyway you could try code like:



Dim ctl as control
For Each ctl In frmMain.Controls
If ctl.Visible = True Then
If ctl.Enabled = True Then
If Left(ctl.Name, 3) = "tbx" Then
ctl.Value = StrConv(ctl.Value, vbProperCase)
End If
End If
End If
Next ctl


Regards

Seamus

clhare
09-17-2007, 07:36 AM
Actually, I am using something from that thread to change just the very first character to upper case. I actually don't want to just change the entire text to propercase because, as noted in the thread, they might have something like "John McDonald" as the name and I don't want to lose the capital D.

I guess what I actually need to know is if there's a way to check and see if the Caps Lock key is on, and if it is, turn it off? Cuz if it's on and the macro does the Prop function from that thread, it's not going to change anything. But if I can turn it off before they even start typing (like before the userform even is loaded), they'll start out in the correct state.

SOS
09-17-2007, 07:51 AM
clhare,

There is - I had a piece of code to check CapsLock status (but it only seems to work in Excel)..I just tried copying it over to Word and it didn't like the word "GetKeyState" but you might want to google that to see if it helps you.

regards

Seamus

fionabolt
09-17-2007, 08:07 AM
Interesting problem.

I just tried this code in wd2003. It worked great:
http://www.freevbcode.com/ShowCode.Asp?ID=1004
:clap:

clhare
09-17-2007, 08:24 AM
Cool! It worked! I just had to call the "ToggleCapsLock" macro and pass "False" to it. Then when I run my template, it turns Caps Lock off. Yea!

Thanks so much!:content: