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

How to force uppercase in a text box? 5

Status
Not open for further replies.

EwS

Programmer
Dec 30, 2002
398
0
0
US
I searched the forum, but what I found (AfterUpdate event and >C) doesn't work. I don't see any AfterUpdate event for a textbox, and putting >C in the DataFormat field of the text box doesn't work.

I need to change the letters to uppercase AS THE USER TYPES THEM. I tried this:

Private Sub myTextBox_Change()
Me.ActiveControl = UCase(Me.ActiveControl)
End Sub

but it puts the cursor at the beginning of the text box after you type each letter, so if I want to type "CUST", I end up with "TSUC".

Is there a way to use UCase() in the Custom format for the DataFormat field?

Thank you.
 
This is what I use often. It forces all letters to be capitalized when they are typed in and leaves other charactes as they are.

Private Sub Text1_KeyPress(KeyAscii As Integer)
'// Make all of the letters capitals.
If KeyAscii >= 97 And KeyAscii <= 122 Then KeyAscii = KeyAscii - 32
End Sub


Thanks and Good Luck!

zemp
 
Try This, it works for me:

Code:
Private Sub myTextBox_Change()
 myTextBox.Text = UCase$(myTextBox.Text)
End Sub

jayare
 
I was curious. I want to do this too but I hate to have to put this code in the keypress event of every textbox. (My app has close to 100 text boxes). Is there a way to pass this at the form level using maybe the form_keydown event?
 
Yes it can be tedious if you have lots of text boxes. Use control arrays, if you can, for such repeditive code. Or create an active X text box control that does this automatically.

I have never tried to control this sort of thing at the form level.

Thanks and Good Luck!

zemp
 

Set the forms keypreview = true and in the...
[tt]
Private Sub Form_KeyPress(KeyAscii As Integer)
KeyAscii = Asc(UCase(Chr(KeyAscii)))
End Sub
[/tt]

Good Luck

 
Try this link: thread222-515700

I have posted a solution there and Hypetia has a excellent solution there as well.

Swi
 
Does this still work, or is it only VBA?

TextBox = StrConv(TextBox, vbUppercase)
 
EwS
There may be a case when you do not want every
Text Box on the Form to be Ucase. In that case,
I would recommend you use a contol array for the
the text boxes you want to Ucase.
Assuming txText(0) through txText(10)
Code:
Private Sub txText_Change(Index As Integer)
 Select case Index
    Case 0 to 8
     txText(Index).Text = Ucase$(txText(Index).Text)
     '--Perhaps you're not concerned w/ 9 & 10-----
 End Select
End Sub
Giving you more control.

jayare
 
A better technique instead of making a control array for just the text boxes which are to return upper case, may be to use vb5prgrmr suggestion and the Tag property:

At design time set the Tag property of those textboxes:
Text1.Tag =&quot;UC&quot;

Then:
Private Sub Form_KeyPress(KeyAscii As Integer)
If TypeOf me.Active Control Is TextBox then
If Me.ActiveControl.Tag = &quot;UC&quot; Then
KeyAscii = Asc(UCase(Chr(KeyAscii)))
End If
End If
End Sub
 
I use a similar routine to capitalise ONLY the first letter of each word in a name or address field if the caps lock is off. The user than doesnt have to worry about capitals at all.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top