+ Reply to Thread
Results 1 to 11 of 11

TextBox SetFocus Problem on UserForm

  1. #1
    Registered User
    Join Date
    12-04-2016
    Location
    CHICAGO US
    MS-Off Ver
    Excel 2016
    Posts
    14

    TextBox SetFocus Problem on UserForm

    Hi, I am having trouble with the setfocus command and I have done a bit of searching but my knowledge of vba is very little.

    I have managed to get the following code with help but the setfocus in the Private Sub UnitCost_Change() is not working.

    I would like a number value to be entered in TextboxControl and on typing a value if the data is not in the correct format a message will appear with an OK Button. When OK is selected I would like the wrong data to be cleared and the cursor back in the TextboxControl.

    The code below is working fine except the SetFocus doesn't appear in the activate control.

    Here is the code in Module mode:
    Please Login or Register  to view this content.
    Here is the code in Userform mode:
    Please Login or Register  to view this content.
    Thanks in advance.
    Last edited by jarekmos; 01-20-2020 at 09:40 PM.

  2. #2
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,448

    Re: TextBox SetFocus Problem on UserForm

    Administrative note

    Post moved to correct forum.

  3. #3
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,448

    Re: TextBox SetFocus Problem on UserForm

    Administrative note
    Please update your profile as necessary to properly reflect the exact version(s) of Excel your question relates to. Members tailor answers based on your Excel version. Your profile does not indicate your version.
    Thanks

  4. #4
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: TextBox SetFocus Problem on UserForm

    This code works for me...Perhaps you should upload a sample file...
    Please Login or Register  to view this content.
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  5. #5
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: TextBox SetFocus Problem on UserForm

    This only removes the last character

    Please Login or Register  to view this content.
    I don't get any issue from the .setfocus on my test file
    Cheers
    Andy
    www.andypope.info

  6. #6
    Forum Expert KOKOSEK's Avatar
    Join Date
    08-03-2018
    Location
    Pole in Yorkshire, UK
    MS-Off Ver
    365/2013
    Posts
    2,743

    Re: TextBox SetFocus Problem on UserForm

    you can check what kind of key user press:

    Please Login or Register  to view this content.
    Happy with my answer * Add Reputation.
    If You are happy with solution, please use Thread tools and mark thread as SOLVED.

  7. #7
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,913

    Re: TextBox SetFocus Problem on UserForm

    Why would you need to set focus to the active control?
    Rory

  8. #8
    Registered User
    Join Date
    12-04-2016
    Location
    CHICAGO US
    MS-Off Ver
    Excel 2016
    Posts
    14

    Re: TextBox SetFocus Problem on UserForm

    Thanks everyone for your responses, but what I wanted was, when I press the enter key and an error message shows up and then I press OK on the error message, then the cursor would jump back onto the active textbox.

    Sintek, the code doesn't work for me because then after every time I press OK on the error message I would have to click on the textbox with my mouse, but I want the cursor to just jump back to the active textbox.

    Rorya, I want to have SetFocus on an active control because I have a lot of textboxs and I don't want to always click on each textbox, instead the cursor would jump to the next textbox once I press the enter key.

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

    Re: TextBox SetFocus Problem on UserForm

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however it has been brought to our attention that the same query has been posted on one or more other forums and you have not provided the required cross-post link(s) here.

    Please see Forum Rule #3 about cross-posting and adjust accordingly. Read this to understand why we (and other sites like us) consider this to be important.

    (Note: this requirement is not optional. No help to be offered until the link is provided.)

    Cross-posted TextBox SetFocus Problem on UserForm
    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!)

  10. #10
    Registered User
    Join Date
    12-04-2016
    Location
    CHICAGO US
    MS-Off Ver
    Excel 2016
    Posts
    14

    Re: TextBox SetFocus Problem on UserForm

    Hi, Ross
    I can't attach a link to the cross-post.

  11. #11
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,913

    Re: TextBox SetFocus Problem on UserForm

    I think you missed my point. The active control already has the focus, otherwise it wouldn’t be active.

+ 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. Userform Login on userform and disabling/enabling userforms controls
    By waimea in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-23-2019, 10:37 AM
  2. Replies: 23
    Last Post: 07-12-2014, 07:09 PM
  3. [SOLVED] Excel Userform: Populate other controls (i.e. textbox & combobox) based on combobox select
    By MileHigh_PhD in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-22-2013, 04:50 PM
  4. Userform Textbox updating a another userform textbox (im stuck!!)
    By wapwap in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-31-2011, 02:56 PM
  5. Index number for controls (eg Textbox) in userform
    By asha3010 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-07-2010, 08:46 AM
  6. Code to format number input in textbox controls (based on tag) in userform
    By asha3010 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 07-05-2010, 01:09 PM
  7. loop controls in userform except one textbox
    By gkisacik in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 03-28-2010, 04:30 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