+ Reply to Thread
Results 1 to 7 of 7

Force SetFocus until input has been made

  1. #1
    Forum Contributor onmyway's Avatar
    Join Date
    09-03-2012
    Location
    Johannesburg, South Africa
    MS-Off Ver
    2013
    Posts
    386

    Force SetFocus until input has been made

    Hi guys,

    I have this code that checks that my TextBox is not empty, and also formats it. But when one tabs through the field, a warning does pop up, but the cursor moves to the next field. How can I change/force the focus to that field until an input has been made?

    i have tried SetFocus

    Here is my code:

    Please Login or Register  to view this content.
    Thank you!
    Last edited by onmyway; 01-30-2015 at 03:04 PM.

  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,258

    Re: Force SetFocus until input has been made

    Hello onmyway,

    This where the argument Cancel becomes your friend. Setting Cancel to True prevents the focus from moving to the next control in the tab order.

    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 Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: Force SetFocus until input has been made

    Hi onmyway,

    Have you tried a SendKeys to do a shift tab to get back to the prior input box?

    See https://msdn.microsoft.com/en-us/lib...ffice.15).aspx

    I normally use a DoEvents in my code with SendKeys to insure they are received and processed correctly.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  4. #4
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Force SetFocus until input has been made

    Onmyway,

    Was about to answer, but Leith beat me to it, glad I did a refresh. The problem with your code was that your exit code runs, THEN exits. So technically the box still had focus. Weird, but basically a timing thing. As Leith said that is when cancel becomes your friend
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  5. #5
    Forum Contributor onmyway's Avatar
    Join Date
    09-03-2012
    Location
    Johannesburg, South Africa
    MS-Off Ver
    2013
    Posts
    386

    Re: Force SetFocus until input has been made

    Hi all, great answers. Thanks a lot!

  6. #6
    Forum Contributor onmyway's Avatar
    Join Date
    09-03-2012
    Location
    Johannesburg, South Africa
    MS-Off Ver
    2013
    Posts
    386

    Re: Force SetFocus until input has been made

    May I ask one more thing in this thread: what line of code can i add that will warn the user that the field may not be blank when tabbing through the field?

  7. #7
    Forum Contributor onmyway's Avatar
    Join Date
    09-03-2012
    Location
    Johannesburg, South Africa
    MS-Off Ver
    2013
    Posts
    386

    Re: Force SetFocus until input has been made

    I did the following: is that OK?

    Please Login or Register  to view this content.

+ 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] Retain Formula when Input is made
    By drakaz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-11-2013, 10:03 AM
  2. Force data input style
    By Armitage2k in forum Excel General
    Replies: 1
    Last Post: 04-22-2012, 06:33 AM
  3. Getting macro to return input made into input box
    By MrPoesiat in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-13-2012, 04:09 PM
  4. Replies: 1
    Last Post: 08-02-2011, 11:48 AM
  5. force input data to be uppercase
    By 435 Gavea in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-16-2007, 10:13 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