Capitalize input

  • Thread starter Thread starter Nalla
  • Start date Start date
N

Nalla

Is it possable to capitalize the first letter of an users input as it is
entered into text box that is on a combo box, by useing code
thanks in advance
 
Nalla said:
Is it possable to capitalize the first letter of an users input as it is
entered into text box that is on a combo box, by useing code
thanks in advance


SoOORY Mean NOT Userform not combobox
 
There are no proper case commands in Excel (unlike Word). But you could
convert the value using the following construct

x = UCase(Mid(x, 1, 1)) & Mid(x, 2)

where x is the string to act upon.

To apply this to a textbox, use the change event

Private Sub TextBox1_Change()
TextBox1.Value = UCase(Mid(TextBox1.Value, 1, 1)) & Mid(TextBox1.Value, 2)
End Sub
 
If you mean captialize first letter of input into text box on userform then
try:

Private Sub TextBox1_Change()
With TextBox1
If Len(.Text) = 1 Then .Text = UCase(.Text)
End With
End Sub

Regards,
Greg
 
Thanks Greg this work beutifully . but one more question how would i
generate the same outcome in each of several text boxes on the same
form..... would a Public Sub achieve this ?
 
Private Sub TextBox1_Change()
Upshift TextBox1
End Sub

Private Sub TextBox2_Change()
Upshift TextBox2
End Sub

'etc.

Private Sub Upshift(ByRef TB As MSForms.TextBox)
With TB
If Len(.Text) = 1 Then .Text = UCase(.Text)
End With
End Sub
 
Nalla said:
Is it possable to capitalize the first letter of an users input as it
is entered into text box that is on a combo box, by useing code
thanks in advance

Another way is to change the text after the user is done typing, like

Private Sub TextBox1_AfterUpdate()

Me.TextBox1.Text = StrConv(Me.TextBox1.Text, vbProperCase)

End Sub

This will change the text to proper case, rather than just capitalizing the
first letter. You may prefer this method if you want to prevent the user
from typing in all caps.
 
Back
Top