ucase on change

S

seeker

I have a textbox that the user wants to have all caps while he types into the
textbox. The following code is in the onchange event for the textbox.

txtNameKey.Text = UCase(txtNameKey.Text)
txtNameKey.SelStart = Len(txtNameKey) + 1

This takes the textbox back to the first letter and overwrites it. I want
it to type the second letter and then third etc. Thanks.
 
D

Dirk Goldgar

seeker said:
I have a textbox that the user wants to have all caps while he types into
the
textbox. The following code is in the onchange event for the textbox.

txtNameKey.Text = UCase(txtNameKey.Text)
txtNameKey.SelStart = Len(txtNameKey) + 1

This takes the textbox back to the first letter and overwrites it. I want
it to type the second letter and then third etc. Thanks.


I don't think I'd use the Change event for this. How about using the
control's KeyPress event instead, to translate each keystroke as it is
typed:

'------ start of code ------
Private Sub txtNameKey_KeyPress(KeyAscii As Integer)

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

End Sub
'------ end of code ------
 
P

Peter Hibbs

You could try this in the KeyPress event of the Text box :-

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

HTH

Peter Hibbs.
 

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

Top