+ Reply to Thread
Results 1 to 8 of 8

Exit sub from user form problem...

  1. #1
    Forum Contributor
    Join Date
    04-27-2006
    Location
    Cayman Islands
    Posts
    379

    Exit sub from user form problem...

    Good morning all, I am having a small issue where I get a runtime error '91' when the Exit Sub command is used from a user form, this is what happens.

    1. I run the macro which assigns some variables then shows UserForm1

    2. On UserForm1 initialising and through use of a command button I sort though all of my data assigning tasks to each piece of data, this all works fine, however when there is no data left this piece of code executes:

    Please Login or Register  to view this content.
    Everything works fine until this point but when it hit's Exit Sub I have a problem. Any ideas what's going wrong?
    Last edited by ChrisMattock; 12-10-2008 at 10:52 AM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    You don't need exit sub, just unload me
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Contributor
    Join Date
    04-27-2006
    Location
    Cayman Islands
    Posts
    379
    That was an awesomely quick reply Roy! Thanks, but now I have removed it I get stuck in an endless loop (I can't even press escape the stop the macro now). When Unload Me is used from UserForm_Initialize where does it start running code from again? The original macro that called the form? If so then it goes back there and the form is called again, my MsgBox is displayed, it unloads, etc. etc.

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    I didn't realise it was part of a loop. maybe

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    04-27-2006
    Location
    Cayman Islands
    Posts
    379
    Well that almost works, however after the form is unloaded it popus up again almost instantly, here is the initial part of the code...

    Please Login or Register  to view this content.
    Then this is what happens with UserForm1

    Please Login or Register  to view this content.
    The following just control the movement of items between two listbox's

    Please Login or Register  to view this content.
    Hope that makes sense, sorry not very good at this, but am assuming the problem occurs when I keep reloading the current form?

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Replace Exit Sub with End
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    04-27-2006
    Location
    Cayman Islands
    Posts
    379
    Yes, yes, yes! That's perfect, and so simple! +rep to you and thanks so much!

  8. #8
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Thanks for the rep 7 glad it helped.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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