+ Reply to Thread
Results 1 to 8 of 8

Escape key on UserForm also cancels the next UserForm to appear?

  1. #1
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Escape key on UserForm also cancels the next UserForm to appear?

    I have a project where two UserForms are shown in succession. Form1 autocloses and then Form2 is loaded almost immediately afterwards.

    But if the user presses escape while Form1 is shown, Form1 closes and Form2 never appears.

    How do I work around this problem while still allowing Form1 to be closed with escape key?

    Is there something I could code in between Form1.Show and Form2.Show to help negate the Escape key action on Form1 carrying onto Form2?


    (Not sure is this helps: Form1 is shown Modal. Form2 is shown Modeless. I want to keep Form2 as modeless.)
    *******************************************************

    HELP WANTED! (Links to Forum threads)
    Trying to create reusable code for Custom Events at Workbook (not Application) level

    *******************************************************

  2. #2
    Forum Expert
    Join Date
    01-12-2007
    Location
    New Jersey
    Posts
    2,127

    Re: Escape key on UserForm also cancels the next UserForm to appear?

    Could you possibly include the Form2.Show code in the Form1_Deactivate event?

    I didn't test this, but am wondering if it would work.

  3. #3
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Escape key on UserForm also cancels the next UserForm to appear?

    Quote Originally Posted by BigBas View Post
    Could you possibly include the Form2.Show code in the Form1_Deactivate event?

    I didn't test this, but am wondering if it would work.
    Hi BigBas, I appreciate your suggestion however I'd prefer not to use this approach. I try to keep my forms encapsulated. Form1 is a template I reuse between projects. Form2 is unique to the current project. (If there is no other solution, I will end up using this but I am hoping there is another way to fix it)

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

    Re: Escape key on UserForm also cancels the next UserForm to appear?

    I'd suggest you provide some code showing how your forms are loaded and unloaded or a sample workbook, and maybe stipulate all your exclusions up-front.
    Everyone who confuses correlation and causation ends up dead.

  5. #5
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Escape key on UserForm also cancels the next UserForm to appear?

    Good to hear from you romperstomper. (BTW see my forum user description - I accepted 100% what you said a while ago!)

    Quote Originally Posted by romperstomper View Post
    I'd suggest you provide some code showing how your forms are loaded and unloaded
    OK here's the code. Form1 = Splash. Form2 = Menu1

    This is calling sub that loads these 2 forms
    Please Login or Register  to view this content.

    Here's the code for Form1 (it's a splash screen)
    Please Login or Register  to view this content.

    Here's the code for loading Form2 (aka Menu1)
    Please Login or Register  to view this content.
    And finally here's the code for Form2 (Menu1)

    Please Login or Register  to view this content.

    Quote Originally Posted by romperstomper View Post
    maybe stipulate all your exclusions up-front.
    Yes I agree. I overlooked specifying the encapsulation requisite upfront. My fault entirely. (Concepts that I use as a matter of course I sometimes overlook specifying as a requirement in threads ).

    Exclusions:
    • Forms to be encapsulated. Form2 should not be loaded from Form1
    • Form1 must be able to be canceled with the Escape key
    • I want to keep Form2 Modeless (I don't care about Form1 - it can be either)
    Last edited by mc84excel; 04-07-2014 at 06:30 PM.

  6. #6
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Escape key on UserForm also cancels the next UserForm to appear?

    FWIW I find your reliance on errors simply to enable a user to press Escape to close a form a bit nasty. I'd do it like this:
    Please Login or Register  to view this content.
    As to why the code doesn't work when you've pressed the Esc key I don't know, but I suspect your method of stopping a bus by driving it off a cliff isn't helping

  7. #7
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Escape key on UserForm also cancels the next UserForm to appear?

    Quote Originally Posted by Kyle123 View Post
    FWIW I find your reliance on errors simply to enable a user to press Escape to close a form a bit nasty.
    Ah. I recently encountered the concept of having the Escape key trigger an Error Handler and I really like the idea (because it guarantees that the procedure will clean up properly if the end user presses cancel while a macro is running).
    I think I got carried away with the newly encountered concept (as I always do) and I started applying this to forms as well. I'm now thinking that's not a good idea on forms (read on to see why!)


    Quote Originally Posted by Kyle123 View Post
    As to why the code doesn't work when you've pressed the Esc key I don't know
    I took your code - or rather the parts I wanted to keep - and it now runs perfectly. Pressing Escape now doesn't trigger a skip on the next form to appear! Thanks Kyle for coming to the rescue again! +1

    It looks like your hunch re errors and Esc Key was right on the mark.


    Quote Originally Posted by Kyle123 View Post
    I suspect your method of stopping a bus by driving it off a cliff isn't helping
    ROTFL. I like your analogy!

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

    Re: Escape key on UserForm also cancels the next UserForm to appear?

    Quote Originally Posted by mc84excel View Post
    Good to hear from you romperstomper. (BTW see my forum user description - I accepted 100% what you said a while ago!)
    Ha - I like it!

+ 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. combining chart userform and data transfer userform into 1 userform
    By H_Kennedy in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 01-04-2014, 07:11 AM
  2. [SOLVED] Excel 2007, Userform Textbox Date Format and Calendar Control Userform
    By riffology in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-03-2014, 06:18 PM
  3. combining chart userform and data transfer userform into 1 userform
    By H_Kennedy in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-03-2014, 12:28 PM
  4. [SOLVED] Open a userform from a userform, but preserve the info in the original userform
    By jfoerch in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-25-2013, 02:38 PM
  5. userform is large.....how to use scrollbar of userform to show all of the userform
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-05-2010, 04:11 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