+ Reply to Thread
Results 1 to 7 of 7

Add Cancel argument to Textbox Exit event

  1. #1
    Registered User
    Join Date
    08-08-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2007
    Posts
    9

    Add Cancel argument to Textbox Exit event

    Does anyone know how to add the below cancel argument, allowing the user to exit the textbox when done?

    "Each UserForm TextBox has an Exit event. There is an named argument Cancel which is a Boolean value. If you set this to True, then the focus will not move to the next control in the Tab Order. It will remain with the TextBox".[/I]


    Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    ??
    ??
    ?? how do I code this?

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,199

    Re: Add Cancel argument to Textbox Exit event

    Hi, Idahoanne,

    allowing the user to exit the textbox when done?
    AFAIR Cancel is used to keep the focus on the textbox.
    It will remain with the TextBox
    If you do not use the Cancel argument the user may leave the textbox.

    Keep the focus on Textbox
    Please Login or Register  to view this content.
    Letting go use this code or omitt the event:
    Please Login or Register  to view this content.
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Registered User
    Join Date
    08-08-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Add Cancel argument to Textbox Exit event

    If I put cancel = true, then the cursor remains in the textbox (which is great while they are entering data), but the user cannot exit the textbox. they cannot hit escape, or use to the mouse to click another button. they are stuck.

    Do you know a way to put in an argument, that allows the user to exit, when done using the textbox?

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Add Cancel argument to Textbox Exit event

    You don't need to do anything for that. By default a user can leave a text box whenever they want. You only need the Cancel argument if you want to stop them - for example they filled it incorrectly.
    Everyone who confuses correlation and causation ends up dead.

  5. #5
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,199

    Re: Add Cancel argument to Textbox Exit event

    Hi, Idahoanne,

    maybe this can give you an idea as you do not supply any hint on a correct filling (here the length of the entry):
    Please Login or Register  to view this content.
    Ciao,
    Holger

  6. #6
    Registered User
    Join Date
    08-08-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Add Cancel argument to Textbox Exit event

    Course_Roster_TEST2.xlsm

    when I use the code above, the cursor does not return to the textbox, it goes back to the Register button. The user has to either click back into the textbox, or hit enter to go back. do you know a way to return the cursor to the textbox? I've attached a copy of the file. thank you for your help with this!

  7. #7
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,199

    Re: Add Cancel argument to Textbox Exit event

    Hi, Idahoanne,

    if it´s UserForm2 you´re talking about the code is working fine: I have to close the UF using the X as no other control is available on that form (using Excel2013 on this). You might consider to get away from letting the users type in every information into textboxes and offer either Listboxes or CombBoxes to choose from instead.

    Ciao,
    Holger

+ 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] Problems with Exit event for Textbox
    By tfurnivall in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-11-2013, 11:03 AM
  2. Cancel argument in event handler passed to subordinate Sub but updated value not returned
    By 6StringJazzer in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-10-2013, 12:56 PM
  3. Textbox Exit Event Cant not be trigger
    By stewegg in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-26-2012, 01:26 PM
  4. Userform Textbox Exit Event to Run Application
    By baisty182 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-29-2010, 12:30 PM
  5. Userform textbox event that fires after I exit the textbox
    By jerseyguy1996 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 02-04-2010, 08:08 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