Results 1 to 7 of 7
  1. #1
    Join Date
    Jul 2004
    Location
    South Dakota
    Posts
    267

    Unanswered: Selecting text in AfterUpdate event

    To All--

    I'm having a little brain fart here...why won't this work.

    I have a text box that in the afterupdate event I want to check some things. Then, depending on those things, I want to select the text in the textbox. Heres the code for selecting the text:

    Code:
    With Text0
            .SetFocus
            .SelStart = 0
            .SelLength = Len(Text0)
        End With
    This works just fine in a button's Click event but not in the textbox's afterupdate event. Please remind me what I'm missing. Thanks.

    C

  2. #2
    Join Date
    May 2008
    Location
    Raleigh, NC
    Posts
    151
    I've just spent about 20 minutes trying to do what you are asking and I'm very frustrated! I think we are both having something more than a brain fart!

    I'll let you know if I figure something out.
    --If its free, take it for what its worth!

  3. #3
    Join Date
    Aug 2008
    Posts
    58
    If you're not ever going to select a fragment of the text, why not just refer to the Text property of the text box control (Text0.Text)? You can then use that string however you please, such as in a query criteria.

    Code:
    WHERE MyField Like "'Text0.Text' & '*'"

  4. #4
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    That doesn't deal with the issue of selecting.

    This works just fine in a button's Click event but not in the textbox's afterupdate event.
    So don't do it in the AfterUpdate!! When things like that don't work in one area but they do in another, there is usually a good reason. In this case, I would say that the reason is that the AfterUpdate event ends in the NEXT control being selected. I know it would annoy me if after I updated a field, the thing just selected what I typed. Maybe you should consider either Undoing what was typed or just moving on?
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  5. #5
    Join Date
    Jul 2004
    Location
    South Dakota
    Posts
    267
    What I'm trying to do is check what the user has just typed in...if it doesn't pass my "test" then I want to alert the user that something needs to be fixed with a MsgBox and then select the text in that textbox. To me it seemed that the best place to do this would be in the AfterUpdate event. I'd rather not wait until the "end" when the user presses OK (or whatever) and then blast them with a bunch of stuff that has to be fixed.

    Any other suggestions would be appreciated. Thanks.

    C

  6. #6
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Have you considered changing the textboxes .ForeColor property instead of selecting the text? E.g. Set the text colour to red if validation fails
    George
    Home | Blog

  7. #7
    Join Date
    Jul 2004
    Location
    South Dakota
    Posts
    267
    Here's my solution:

    Basically I've ended up moving the code to the textbox's Exit event. Here I'm able to cancel the Exit after validating the input and then select the text. I also took georgev's advice and changed some colors to alert the user as well. Thanks for all the advice.

    C

Posting Permissions

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