+ Reply to Thread
Results 1 to 4 of 4

Highlight A Textbox For User Reentry After Incorrect Entry

  1. #1
    Forum Contributor
    Join Date
    06-15-2009
    Location
    Ontario, canada
    MS-Off Ver
    Office 365
    Posts
    371

    Highlight A Textbox For User Reentry After Incorrect Entry

    I've sought out answers to this question many times, and have found solutions, but they didn't appear to work in my case. I think, unproven, the showmodal property of a userform has an effect on the success of many of the readily available solutions found through searches. (involving setfocus and complex selection formula)

    I have a userform. The user enters a value in a textbox (tab position 2). A beforeupdate event triggers and checks the appropriateness of the data entered into the textbox by the user.
    If an inappropriate entry is identified, the user is notified, and the offending entry is overwritten with a default value. The user is then able to re-enter another value.

    As it works now, after the entry is replaced with the default, the highlighting of the textbox awaiting data entry is at the next textbox in tabular order. (tab order 3).

    How can I keep the the selection highlighting in the original field (tab order 2) after the correction is made rather than jumping to the next? With this, the user must click and highlight the contents of the original textbox ... an annoyance and time consuming when entering a lot of data.

    When I use SetFocus, nothing happens. The value in the textbox (tab stop 3) is highlighted, not the original.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Highlight A Textbox For User Reentry After Incorrect Entry

    Hello Jenn68,

    In the BeforeUpdate event, there is an input argument called Cancel. After you check the input, if it fails then set Cancel = True. This will prevent tabbing to the next control. You can then highlight the entered selection.

    Here is an example...
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Contributor
    Join Date
    06-15-2009
    Location
    Ontario, canada
    MS-Off Ver
    Office 365
    Posts
    371

    Re: Highlight A Textbox For User Reentry After Incorrect Entry

    Hi Leith,

    Thank you so much for your support! I added the line CANCEL = True which has stopped the focus jumping to the next textbox.
    But the text selection (highlighting) still seems to be failing. If I recall, this may have been a recurring challenge I have had (as mentioned in my initial post). The result I get is simply a blinking cursor after the last character of the defaulted text in the textbox.

    Here is my code adapted based on Leith's comments.

    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    06-15-2009
    Location
    Ontario, canada
    MS-Off Ver
    Office 365
    Posts
    371

    Re: Highlight A Textbox For User Reentry After Incorrect Entry

    Is anyone able to suggest a possible solution? Or can I assume I hit a dead end?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] If rows has a new entry performs a highlight at the previous entry
    By emina002 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-05-2018, 10:53 PM
  2. [SOLVED] Highlight textbox if date <=60 days referencing an array as textbox numbers
    By nigelog in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 03-23-2017, 11:43 AM
  3. add a string of locked text to vba textbox based on entry in the same textbox
    By yoursamrit2000 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-21-2014, 11:48 PM
  4. Convert User Form textbox entry to numerical value
    By MeBeMel in forum Excel General
    Replies: 1
    Last Post: 05-12-2014, 12:19 AM
  5. Set Max and Min limits on calculated textbox based on another textbox entry
    By kpinkerman in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-13-2013, 04:54 PM
  6. [SOLVED] VBA UserForm - Have entry in TextBox fill Another TextBox by VLOOKUP
    By msquared99 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-26-2012, 10:24 PM
  7. Replies: 2
    Last Post: 07-09-2012, 02:05 AM

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