-
Everytime someone types something into a text box I want the first letter of every word to be a capitol....for example turn every letter capitol after every space.
so in the keypress event
if someone typed
john carl
it would change it to John Carl
-------------------------------
How would i go about doing that?
-
In the change event, make a cycle finding spaces and convert the string.
-
Here it is......
Hi,
Here is the code for your query...
Private Sub Text1_Change()
Text1.SelStart = Len(Text1) + 1
Text1 = StrConv(Text1.Text, vbProperCase)
End Sub
This will convert the first letter of each string to uppercase as john smith to John Smith.
Cheers!!!
-
This would not capitalise the first letter so you need something like
Code:
If Left$(MyStr, 1) <> " " Then MyStr = UCase$(Left$(MyStr, 1)) & Right$(MyStr, Len(MyStr) - 1)
i = 1
Do While InStr(i, MyStr, " ")
MyChars = Mid$(MyStr, InStr(i, MyStr, " "), 2)
i = InStr(i, MyStr, " ") + 1 ' Go past space...
RepChars = UCase$(MyChars)
MyStr = Replace(MyStr, MyChars, RepChars)
Loop
NB This is highly inefficient, but it is off the top of my head. Might give you a starting point though.
Cheers,
Paul.
-
One problem
I got vb3, doesnt support that.
-
Hmm. Try adding this to text1_change. I never had anything below vb4 so don't know what you can't do?
Code:
If Len(Text1.Text) = 1 Then
Text1.Text = UCase$(Text1.Text)
Else
If Mid$(Text1.Text, Len(Text1.Text) - 1, 1) = " " Then
Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1) _
& UCase$(Right(Text1.Text, 1))
End If
End If
Text1.SelStart = Len(Text1.Text)
-
Oops
Sorry. Add this to the top of the code :
Code:
If Len(Text1.Text) = 0 Then Exit Sub
I hate it when I find bugs!