Apr 5th, 2008, 07:42 AM
#1
Thread Starter
Lively Member
[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
Apr 5th, 2008, 08:04 AM
#2
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
Apr 5th, 2008, 08:19 AM
#3
Thread Starter
Lively Member
Re: First letter capitalized
Thanks DidiRev, this makes the name right (not backward) but never capitalizes the first letter when txtName losess focus.
Apr 5th, 2008, 08:29 AM
#4
Re: First letter capitalized
Attached Files
Apr 5th, 2008, 08:35 AM
#5
Thread Starter
Lively Member
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.
Apr 5th, 2008, 10:01 AM
#6
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
Apr 5th, 2008, 01:04 PM
#7
Thread Starter
Lively Member
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.
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width