Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Re-starting a project but avoiding recursion???
Ladies and Gents -
I have a project, several subs and functions and forms. While running one of the subs, it is checking to see if the user wants to add some new data. If that is true, then it creates a new entry on the worksheet (I am using the worksheet like a database). But then, at that point, after the new data is added at the end of the sheet, I need it to re-start, by running the "main" macro that the user normally activates when the sheet first opens (I have a button on the worksheet for this). If I use the Call method, it seems that there is some sort of recursion going on. Weird things happen... including a Windows fatal error. How can I jump out of a sub, and then restart the entire project by starting the original macro again? Thanks! |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Re-starting a project but avoiding recursion???
Bit hard without knowing what code is running and how you are interrupting it
for the user to enter data. Are you using an Input box or what? Can you test for the user entering the data and then use End statement. (Look up 'End' in Help for more info on what it does. If the above doesn't help then perhaps you can post a snippet of your code and explain what is happening for the user interaction part. -- Regards, OssieMac "Dan" wrote: Ladies and Gents - I have a project, several subs and functions and forms. While running one of the subs, it is checking to see if the user wants to add some new data. If that is true, then it creates a new entry on the worksheet (I am using the worksheet like a database). But then, at that point, after the new data is added at the end of the sheet, I need it to re-start, by running the "main" macro that the user normally activates when the sheet first opens (I have a button on the worksheet for this). If I use the Call method, it seems that there is some sort of recursion going on. Weird things happen... including a Windows fatal error. How can I jump out of a sub, and then restart the entire project by starting the original macro again? Thanks! |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Re-starting a project but avoiding recursion???
OssieMac -
Thanks - There is a ton of code in here, but I think I can describe it a lot better than I did the first time: When the worksheet opens, it triggers a Form to activate. This form has a lot of data on it for the user to display / edit. The data comes from the worksheet. On that form, there are some combo-boxes. One of them lists "project names", and the combobox is also loaded with "Add New Project", allowing the user to add a new project. If he clicks on this, it brings up a form for entering some new data, and it appends that new data in the worksheet. This is where the problem is. If the user doesn't choose to add a new project, but instead chooses an existing one from the combo-box, then that subroutine retrieves the data from the worksheet and displays it on that main form. But if the user chooses to add a new project, it should add that new data to the worksheet, but then it needs to exit that routine and re-load the main form. I had used Call Userform_Activate but this appears to be really, really bad. I think what I really need is a way to re-start the whole project (by re-loading the main form and killing the subroutine) after the new data is added to the worksheet. The code (a subroutine) is part of the main Form (it's not in a module). Could that be a problem? I am not clear on when code should be in a module, versus inside the form. Any help is appreciated! Thanks. "OssieMac" wrote: Bit hard without knowing what code is running and how you are interrupting it for the user to enter data. Are you using an Input box or what? Can you test for the user entering the data and then use End statement. (Look up 'End' in Help for more info on what it does. If the above doesn't help then perhaps you can post a snippet of your code and explain what is happening for the user interaction part. -- Regards, OssieMac "Dan" wrote: Ladies and Gents - I have a project, several subs and functions and forms. While running one of the subs, it is checking to see if the user wants to add some new data. If that is true, then it creates a new entry on the worksheet (I am using the worksheet like a database). But then, at that point, after the new data is added at the end of the sheet, I need it to re-start, by running the "main" macro that the user normally activates when the sheet first opens (I have a button on the worksheet for this). If I use the Call method, it seems that there is some sort of recursion going on. Weird things happen... including a Windows fatal error. How can I jump out of a sub, and then restart the entire project by starting the original macro again? Thanks! |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Re-starting a project but avoiding recursion???
About your comment 'not clear on when code should be in a module'. I usually
place any code which might need to be called from another routine into a module. Then the only code required in the Event routine is 'Call Whatever' (including any parameters if required.) The same code can then be called from any other procedure. Still not overly sure about all that you are trying to achieve but the following little snippets might help. There are a few things you can do with controls to control what the user can actually do. Example you can use the same command button to Find a record and change it to Save record so that the user must save before finding a new one. Sub CalledRoutine() 'Called from Userform1 FindnSave_Click() event Select Case UserForm1.FindnSave.Caption Case "Find" 'Put code in here to Find the record then change caption to Save UserForm1.FindnSave.Caption = "Save" Case "Save" 'Put code in here to Save the record then change caption to Find UserForm1.FindnSave.Caption = "Find" End Select End Sub Code like this is also handy to disable other buttons like Add New Record after a find routine and re-enable it after the save etc. UserForm1.AddNewRecord.Enabled = False I would place all the above code in a module with Case statements so that you can call it from any event procedure or from anywhere else in your code. -- Regards, OssieMac "Dan" wrote: OssieMac - Thanks - There is a ton of code in here, but I think I can describe it a lot better than I did the first time: When the worksheet opens, it triggers a Form to activate. This form has a lot of data on it for the user to display / edit. The data comes from the worksheet. On that form, there are some combo-boxes. One of them lists "project names", and the combobox is also loaded with "Add New Project", allowing the user to add a new project. If he clicks on this, it brings up a form for entering some new data, and it appends that new data in the worksheet. This is where the problem is. If the user doesn't choose to add a new project, but instead chooses an existing one from the combo-box, then that subroutine retrieves the data from the worksheet and displays it on that main form. But if the user chooses to add a new project, it should add that new data to the worksheet, but then it needs to exit that routine and re-load the main form. I had used Call Userform_Activate but this appears to be really, really bad. I think what I really need is a way to re-start the whole project (by re-loading the main form and killing the subroutine) after the new data is added to the worksheet. The code (a subroutine) is part of the main Form (it's not in a module). Could that be a problem? I am not clear on when code should be in a module, versus inside the form. Any help is appreciated! Thanks. "OssieMac" wrote: Bit hard without knowing what code is running and how you are interrupting it for the user to enter data. Are you using an Input box or what? Can you test for the user entering the data and then use End statement. (Look up 'End' in Help for more info on what it does. If the above doesn't help then perhaps you can post a snippet of your code and explain what is happening for the user interaction part. -- Regards, OssieMac "Dan" wrote: Ladies and Gents - I have a project, several subs and functions and forms. While running one of the subs, it is checking to see if the user wants to add some new data. If that is true, then it creates a new entry on the worksheet (I am using the worksheet like a database). But then, at that point, after the new data is added at the end of the sheet, I need it to re-start, by running the "main" macro that the user normally activates when the sheet first opens (I have a button on the worksheet for this). If I use the Call method, it seems that there is some sort of recursion going on. Weird things happen... including a Windows fatal error. How can I jump out of a sub, and then restart the entire project by starting the original macro again? Thanks! |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Managing Multiple Projects: Avoiding Project Overload | Excel Discussion (Misc queries) | |||
Recursion in VBA macros? | Excel Programming | |||
Abort recursion | Excel Programming | |||
Recursion | Excel Programming | |||
Worksheet_Change Recursion ARGHH! | Excel Programming |