+ Reply to Thread
Results 1 to 8 of 8

Textbox focus

  1. #1
    Registered User
    Join Date
    01-29-2013
    Location
    texas
    MS-Off Ver
    Excel 2010
    Posts
    68

    Textbox focus

    txtAmt resides on a user form and is loaded with a default value from an adjacent cell in the initalize event.
    When the form loads I would like text in the textbox to be highlighted with the curser left justified so that if the user doesn't accept the default value he can overwrite the value without first double-clickng.

    I guess I need the textbox to be pre-double-clicked.

    Possible?

    thanks

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Textbox focus

    This will do the selection part.
    Please Login or Register  to view this content.
    To have the textbox have focus when the form opens right click the form and select Tab Order.

    Then move the textbox to the top of the list.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    01-29-2013
    Location
    texas
    MS-Off Ver
    Excel 2010
    Posts
    68

    Re: Textbox focus

    Here is a bit of my code
    Please Login or Register  to view this content.
    However this still leaves the curser to the right of the default entry

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Textbox focus

    The code I posted needs to go after the code that populates the textbox.

    If it's not then Len(txtAmt.Value) will be 0.

    Please Login or Register  to view this content.
    By the way, it's not a good idea to change the TabIndex of a control at runtime, it can have an affect on the TabIndex of the other controls.

  5. #5
    Registered User
    Join Date
    01-29-2013
    Location
    texas
    MS-Off Ver
    Excel 2010
    Posts
    68

    Re: Textbox focus

    I see now I need to move your code below the point where I set txtAmt.text to amtpaid to get the correct length.
    Since we have the grandkids tonight I'm going to check out for this evening.
    Thanks for your help and patience.

  6. #6
    Registered User
    Join Date
    01-29-2013
    Location
    texas
    MS-Off Ver
    Excel 2010
    Posts
    68

    Re: Textbox focus

    Yes, I understand about the Tabindex, but if the default entry is "stock" then more of the form is visible and those textboxes' tabindexes are accounted for. I'll check the fix in the am. I was able to accomplish this task in VB6 but I don't remember how. Maybe there were more properties available in the textbox.

    Thanks again

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Textbox focus

    If there's a problem with focus going to the controls on the hidden part of the form then disable them until the form becomes visible.

  8. #8
    Registered User
    Join Date
    01-29-2013
    Location
    texas
    MS-Off Ver
    Excel 2010
    Posts
    68

    Re: Textbox focus

    Couldn't stand it, I checked and it does exactly as I wanted.

    Thanks again Norie.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1