+ Reply to Thread
Results 1 to 8 of 8

Overcome Infinite Loop Under Specific Condition

  1. #1
    Forum Contributor
    Join Date
    06-18-2007
    Location
    Kiama, Australia
    MS-Off Ver
    365
    Posts
    119

    Question Overcome Infinite Loop Under Specific Condition

    Hi Fellow Excellers,

    In the attached file if ComboBox2 (Event) is empty and the user attempts to close the file the "ComboBox2_LostFocus()" procedure initiates an infinite loop and Excel cannot be closed. For the life of me I cannot figure out how to prevent this from occurring. Any ideas?
    Attached Files Attached Files

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,377

    Re: Overcome Infinite Loop Under Specific Condition

    Try putting this at the start of both LostFocus event handlers:

    Please Login or Register  to view this content.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Contributor
    Join Date
    06-18-2007
    Location
    Kiama, Australia
    MS-Off Ver
    365
    Posts
    119

    Re: Overcome Infinite Loop Under Specific Condition

    Sorry that will not work.
    I'm actually testing if ComboBox2 is empty when it loses focus and displaying a message box if it is.
    I need some way of overriding the message box if the user is closing the file.

  4. #4
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Overcome Infinite Loop Under Specific Condition

    This issue doesn't apply to my Mac (no ActiveX) but I wonder, does the LostFocus event fire before or after the BeforeClose event?

    If the order is BeforeClose then LostFocus the BeforeClose event could set a global boolean that can be tested by LostFocus.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  5. #5
    Forum Contributor
    Join Date
    06-18-2007
    Location
    Kiama, Australia
    MS-Off Ver
    365
    Posts
    119

    Re: Overcome Infinite Loop Under Specific Condition

    I though of that.
    Unfortunately the sequence appears to be LostFocus then BeforeClose.

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,377

    Re: Overcome Infinite Loop Under Specific Condition

    When you say, "that will not work", did you try it?

    I put that code in, cleared both combo boxes and closed the workbook ... no issue with an infinite loop. Don't know how it fares in more normal circumstances.

  7. #7
    Forum Contributor
    Join Date
    06-18-2007
    Location
    Kiama, Australia
    MS-Off Ver
    365
    Posts
    119

    Re: Overcome Infinite Loop Under Specific Condition

    Yes I did.
    Agreed that it does solve the infinite loop.
    However it has an adverse effect upon normal operations.
    Users are no longer warned to nominate an event prior to entering a result.

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,377

    Re: Overcome Infinite Loop Under Specific Condition

    Don't really want to initiate an infinite loop to test it, but maybe you could create a "loop counter" ... probably needs to be a global or static variable. You then need to decide where best to reset it, increment it and test it. Presumably, the test would be, "if > 1, then exit sub"

+ 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. Infinite loop problem.
    By iecbso in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-21-2015, 08:06 AM
  2. Infinite Loop
    By amphinomos in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-20-2015, 07:56 AM
  3. Why is my loop infinite, and how can I fix it?
    By Mrowe in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-13-2012, 02:48 PM
  4. [SOLVED] VBA infinite loop
    By kamelkid2 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-13-2012, 12:20 PM
  5. Infinite Loop
    By randell.graybill in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-12-2010, 10:44 PM
  6. Infinite Loop
    By phong919 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 01-22-2010, 04:56 PM
  7. For Next Infinite Loop
    By Naji in forum Excel General
    Replies: 5
    Last Post: 01-13-2006, 03:00 PM

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