+ Reply to Thread
Results 1 to 5 of 5

Userform Macro to stop Main sub?

  1. #1
    Forum Contributor vamosj's Avatar
    Join Date
    04-23-2004
    Location
    Oregon
    MS-Off Ver
    2010
    Posts
    294

    Userform Macro to stop Main sub?

    I am setting up a work rotation spreadsheet that will allow me to create our rotation at the click of a button once I've filled out some data prior too (position, dates, etc...)

    Now I have a Userform that will pop up and ask me to replace a body if they are working the exact same day two weeks in a row (i.e.. If they worked Tuesday one week, they can't work it again the next week) by using a combobox.

    Now if someone cancels the userform without selecting anything from the combobox is there a command I could use that would not only stop the userform macro, but the original macro that pointed to it? I've thought about just using an empty cell to put a 1/0 in to show if a selection was made or not, but in the spirit of learning, I'd figure I'd try and find out if there was actual code to do something like this.


    Simple Explanation of Problem:
    Main Macro Runs ----> Needs to replace someone ----> Main Macro opens Useform to allow selection ----> Person decides to exit out/Cancel without making a selection ----> Userform macro realizes it's empty so exits ----> Main macro keeps on a truckin..

    What I'd like to see happen:
    Main Macro Runs ----> Needs to replace someone ----> Main Macro opens Useform to allow selection ----> Person decides to exit out/Cancel without making a selection ----> Userform macro realizes it's empty so exits ----> Main macro stops also..
    Janos S. Vamos
    Data Systems Technician/Fire Controlman PO1(SW/AW)
    US Navy Retired


    Remember, Record Macro can be your friend for figuring out solutions.

    Good or Bad, let me know how I did by clicking on the "Add Reputation" * just to the lower left of here. it only takes a few seconds to let someone know.

  2. #2
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Userform Macro to stop Main sub?

    It certainly can be done, but it is hard to suggest an answer without seeing the code for both the user form and the main macro. Can you post a dummy workbook with sensitive info taken out?
    Be fore warned, I regularly post drunk. So don't take offence (too much) to what I say.
    I am the real 'Napster'
    The Grid. A digital frontier. I tried to picture clusters of information as they moved through the computer. What did they look like? Ships? motorcycles? Were the circuits like freeways? I kept dreaming of a world I thought I'd never see. And then, one day...

    If you receive help please give thanks. Click the * in the bottom left hand corner.

    snb's VBA Help Files

  3. #3
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: Userform Macro to stop Main sub?

    It has been my impression that the normal way to return information from a userform is via a public variable in the standard Module which called the userform.

    Thus you could place something like:

    Please Login or Register  to view this content.
    Usually at the top of your module, outside of any subroutine or function.

    Then the userform can set this variable as true or false depending upon whether someone cancels the userform without selecting anything from the combobox.

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,440

    Re: Userform Macro to stop Main sub?

    I add a read-only property to the userform to determine whether the user decided to cancel the form. I also assume the default action is to cancel.

    userform with 2 command buttons.
    CommandButton1 caption is "Cancel"
    commandbutton2 caption is "Continue"

    userform code
    Please Login or Register  to view this content.

    Standard code module.
    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  5. #5
    Forum Contributor vamosj's Avatar
    Join Date
    04-23-2004
    Location
    Oregon
    MS-Off Ver
    2010
    Posts
    294

    Re: Userform Macro to stop Main sub?

    I've uploaded my spreadsheet with the names changed (to protect the innocent).

    Start on the Planner Sheet

    The Picture of the Calendar is where I have the macro assigned to.


    This is incomplete so I hope you don't run into any problems. But if you want to step through it you can see about midway through the code an area that shows "find someone else for a bye week." This is where it opens the userform to allow the person to manually select the person. And please don't make fun of the code I'm still pretty raw at this.
    Attached Files Attached Files
    Last edited by vamosj; 05-19-2012 at 02:27 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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