+ Reply to Thread
Results 1 to 4 of 4

How to set cursor back to textbox on a userform when validating data?

  1. #1
    Registered User
    Join Date
    04-04-2016
    Location
    USA
    MS-Off Ver
    2010
    Posts
    29

    Post How to set cursor back to textbox on a userform when validating data?

    I have a userform that takes userinput into textboxes and stores them into cells of excel sheet. When I am trying to do data validation on the last command button ("save") on the userform. I am not able to set the focus back into the textbox.

    Code:
    Please Login or Register  to view this content.
    The full file is attached for reference. Please check the Add_InventoryBP Userform for the complete code.

    Thanks for your help
    excelkann
    Attached Files Attached Files

  2. #2
    Forum Contributor
    Join Date
    09-03-2015
    Location
    IE
    MS-Off Ver
    2003 - 2016
    Posts
    258

    Re: How to set cursor back to textbox on a userform when validating data?

    Try adding
    Please Login or Register  to view this content.
    after you set focus to a textbox, otherwise a couple of lines down, focus is set to yet another textbox...

    But I think you need to re-do that code - you could, for example, do something like
    Please Login or Register  to view this content.
    It would even be possible to loop all your controls and all the associated ranges with a small edit to that and adding 2 or 3 more lines.

    (Comment based on message text only - haven't viewed your file)
    Last edited by grimes0332; 04-22-2016 at 10:54 AM.

  3. #3
    Registered User
    Join Date
    04-04-2016
    Location
    USA
    MS-Off Ver
    2010
    Posts
    29

    Re: How to set cursor back to textbox on a userform when validating data?

    Is there a substitute for Code
    Please Login or Register  to view this content.
    after setting the focus back to textbox . I would like the program to move further and do the other lines of code and exiting sub here will not make it happen.

    Essentially, I would like the program to check for duplicate base product, if yes- place cursor back to base product text box , allow user to correct himself and store corrected value to excel and then move forward to sub product text box and repeat the same process.

  4. #4
    Forum Contributor
    Join Date
    09-03-2015
    Location
    IE
    MS-Off Ver
    2003 - 2016
    Posts
    258

    Re: How to set cursor back to textbox on a userform when validating data?

    place cursor back to base product text box , allow user to correct himself and store corrected value to excel and then move forward to sub product
    Once you set focus to the control, you have to exit the procedure to allow the user to make changes then run the Save procedure again. If the changes were successful then that control will not fail the check next time.

    If you want to check all controls first then you will have to rewrite, but it's not difficult. You loop through all controls to check, use the CountIf function to determine if the control contents are unique and if not, build a message to display to the user. If, at the end of the control loop the message string contains text then display the message to the user and exit the sub.

    It would be a lot simpler to simply exit as soon as a non unique entry was found.

+ 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] Userform to search worksheet and display data back to the userform
    By zip247 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-05-2015, 05:46 AM
  2. Return cursor to textbox after data transfer to cell
    By Idahoanne in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 04-04-2014, 02:23 PM
  3. Replies: 4
    Last Post: 01-29-2014, 05:53 AM
  4. Checking and Validating a textbox IF.....
    By Shacker in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-13-2013, 11:57 AM
  5. Set active cursor in TextBox (blinking cursor)
    By Rick_Stanich in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-17-2009, 10:54 PM
  6. Move cursor to textbox in a userform
    By jgmiddel in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-29-2006, 09:55 AM
  7. validating input in textbox
    By Jean-Pierre D via OfficeKB.com in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-15-2005, 04:05 PM

Tags for this Thread

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