Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
dan dan is offline
external usenet poster
 
Posts: 866
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default 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   Report Post  
Posted to microsoft.public.excel.programming
dan dan is offline
external usenet poster
 
Posts: 866
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Managing Multiple Projects: Avoiding Project Overload Duncan[_2_] Excel Discussion (Misc queries) 2 January 7th 08 02:29 PM
Recursion in VBA macros? Peter Chatterton[_4_] Excel Programming 5 November 27th 06 07:27 PM
Abort recursion Mike NG Excel Programming 2 June 29th 05 09:08 AM
Recursion Mike NG Excel Programming 4 June 2nd 05 11:07 PM
Worksheet_Change Recursion ARGHH! DBAL[_2_] Excel Programming 6 July 1st 04 11:55 PM


All times are GMT +1. The time now is 06:29 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"