[RESOLVED] First letter capitalized
I am trying to capitalize the first letter in txtName using this code. It doe's capitalize the letter but it is backword, mary becomes Yram. I seem to be missing some piece of the code. Thanks for any help.
Code:
Private Sub txtName_Change()
txtName = StrConv(txtName, vbProperCase)
End Sub
Re: First letter capitalized
First letter of every word?
For one, even though .Text is the default property of a TextBox, you should still explicitly state it in your code:
Code:
Private Sub txtName_Change()
txtName.Text = StrConv(txtName.Text, vbProperCase)
End Sub
Also, you shouldn't put this in the Change() event. That's why it's going backwards. Try the Validate() event (when the control loses focus):
Code:
Private Sub Text1_Validate(Cancel As Boolean)
Text1.Text = StrConv(Text1.Text, vbProperCase)
End Sub
Re: First letter capitalized
Thanks DidiRev, this makes the name right (not backward) but never capitalizes the first letter when txtName losess focus.
1 Attachment(s)
Re: First letter capitalized
Re: First letter capitalized
DigiRev, Your code does work as you said. I wrote a quick sample project and it worked. I need to play with this and find the right place or method to use it in my project. Thanks for your help. I will let you know if I get this to work.
Re: First letter capitalized
You can do it in the Change event if you want to. Just do this.
Code:
Private Sub txtName_Change()
txtName.Text = StrConv(txtName, vbProperCase)
txtName.SelStart = Len(txtName.Text)
End Sub
Re: [RESOLVED] First letter capitalized
Thanks MartinLiss, that works exactly as I want. I am going to play with DigiRev's code to figure out how to make it work in a future project.