Need Help To Make First Letter Of All Words In A Textbox To Uppercase

so, i have this code to convert first letter of word to uppercase:

Private Sub txtFields_Change(Index As Integer)

txtFields(Index).Text = UCase$(Left(txtFields(Index).Text, 1)) & LCase$(Mid$(txtFields(Index).Text, 2))
txtFields(Index).SelStart = Len(txtFields(Index).Text)
End Sub

but, this was before i realize that i'm actually working with textboxes where more than two words are entered, i need some help with this code so that first letter of all words in a textbox will become uppercase...I'm using Multiline Option in textbox.

anyone, pls? tnx.

hi clarkpoon, try this...

need a command button and a listbox

just change the input string to your data

Private Sub Command1_Click()
Dim s, x, y, z As String
Dim i, n As Integer
Dim spwords() As String

'change s to your input data 
s = "string1 string2 string3 string4 string5 string6 string7"


' Split the string at the space characters.
spwords() = Split(s, " ")

For i = 0 To UBound(spwords)
     
   'get the first character and change to upper case
   x = spwords(i)
   y = UCase(Mid(x, 1, 1))
 
   'get the remaining characters
   n = Len(x)
   z = y & Mid(x, 2, n - 1)
   
  List1.AddItem z
   
Next

End Sub

How about one line...

Option Explicit

Private Sub Form_Load()
Dim S As String
S = "string1 string2 string3 string4 string5 string6 string7"

S = StrConv(S, vbProperCase)
Debug.Print S

End Sub

Good Luck

cguan_77

I'm using only one Textbox with a Multiline optione enabled. thats it...and both are not working or can solve it ;)

I'm using

Text1

in form.


Thanks for fast reply!!!

Are you using .NET? if so you are in wrong forum...
but this works for me

Option Explicit

Private Sub Form_Load()
Dim S As String
S = "string1" & vbNewLine & "string2" & vbNewLine & "string3" & vbNewLine & "string4" & vbNewLine
S = S & "string5" & vbNewLine & "string6" & vbNewLine & "string7" & vbNewLine & "string8"
Text1.Text = S
End Sub

Private Sub Command1_Click()
Text1.Text = StrConv(Text1.Text, vbProperCase)
End Sub

Its working Now :)
Very Very thanks bro :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.