What is the best way to change(keep) every string on your form in uppercase.I don't want to allow lowercase in my input boxes.
Any help will bw appreciated.
Thanks. ;)
Printable View
What is the best way to change(keep) every string on your form in uppercase.I don't want to allow lowercase in my input boxes.
Any help will bw appreciated.
Thanks. ;)
Try the UCase funtion.
Use the keydown event on your text box and put something like this in to it.
txtText.text = UCase(txtText.text)
Private Sub Text1_KeyPress(KeyAscii As Integer)
Text1.Text = UCase(chr(KeyAscii))
End Sub
this way, each character is converted to upper case as it's entered.
Small mistake in mcleran's code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
KeyAscii = Asc(UCase(chr(KeyAscii)))
End Sub
I use a slightly more complicated method - this allows for users who copy and paste stuff into input boxes (and, yes, quite a few do).
Include this sub in a module;
Sub FormatTextbox(ThisTextBox As TextBox, ThisFormat As Integer)
Dim OldSelStart As Integer
OldSelStart = ThisTextBox.SelStart
ThisTextBox.Text = StrConv(ThisTextBox.Text, ThisFormat)
ThisTextBox.SelStart = OldSelStart
End Sub
In your TextBox1.Change event put;
FormatTextBox TextBox1, vbUpperCase
Now the box will be formatted UPPERCASE at all times, whether it is changed in code, by a user, by a copy/paste, by keypresses, by a database etc etc etc...
You can use vbLowerCase, vbProperCase etc as well if you like.
------------------
Mark "Buzby" Beeton
VB Developer
[email protected]
Ok That work quite well.
But I have another question?
I don't want to put this code after every keypress event of a textbox on every form.(That is about 60 textboxes on 6 forms).
Is there a way I can code my program with a few lines that will change every string to uppercase using a public sub or function.(form gotfocus or load etc.)
Thanks. ;)
Although I've only used them once you can achieve many wonderful things with the WithEvents function - see this tip for more information;;
http://www.vb-world.net/controls/tip133.html
------------------
Mark "Buzby" Beeton
VB Developer
[email protected]
Thanks for all your help - I seemed to work it out.
:) :) :) :) ;) ;)