Results 1 to 7 of 7

Thread: [RESOLVED] First letter capitalized

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2007
    Posts
    73

    Resolved [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

  2. #2
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    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

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Apr 2007
    Posts
    73

    Re: First letter capitalized

    Thanks DidiRev, this makes the name right (not backward) but never capitalizes the first letter when txtName losess focus.

  4. #4
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: First letter capitalized

    You sure? Run this...
    Attached Files Attached Files

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Apr 2007
    Posts
    73

    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.

  6. #6
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    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

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Apr 2007
    Posts
    73

    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
  •  



Click Here to Expand Forum to Full Width