Hello,
To summarize, I have the following.
1. An array variable, declared as Public in the declarations section of the module.
2. A sub procedure that populates the array variable, and calls a MakeForm sub procedure.
3. A MakeForm subprocedure that uses the array values to create the form and also adds code to certain controls on the form, using CreateEventProc, InsertLines, etc.
The interesting (or frustrating) thing is, that the MakeForm procedure is called from the last line of "2.". I've placed message boxes at the very end of "2.", even after the Call MakeForm line. In the message box, I put Ubound(MyArrayVar). Everything is fine. But if I reference the array variable from the form itself, I get Error #9, subscript out of range, and I believe this means that my array variable has been killed.
Likewise, if I comment out the line that calls MakeForm from "1.", and comment out the message box there, and then I go and create my own new form and put on it a command button that says msgbox ubound(MyArrayVar), everything is fine.
If I let the MakeForm procedure run through as normal, then go and create my own form, using msgbox ubound(MyArrayVar), then I get the Error #9 again.
So the short version of the long story is:
I am confident that by declaring a Public variable in the declarations section of a module, that you will have a variable available for use as long as the application is running, regardless what other procedures are run between assigning a value to the variable and calling the variable. Is this correct do you think?
So how is it, possibly, that my array variable is getting wiped out here, when, at the end of my Call MakeForm statement, and just before the final End Sub, it is still available to other class modules, etc.??
Sorry for the long note. As you can see, I've spent a lot of time on this. Any help you can provide is very much appreciated.
Thanking you in advance.
-Mike
To summarize, I have the following.
1. An array variable, declared as Public in the declarations section of the module.
2. A sub procedure that populates the array variable, and calls a MakeForm sub procedure.
3. A MakeForm subprocedure that uses the array values to create the form and also adds code to certain controls on the form, using CreateEventProc, InsertLines, etc.
The interesting (or frustrating) thing is, that the MakeForm procedure is called from the last line of "2.". I've placed message boxes at the very end of "2.", even after the Call MakeForm line. In the message box, I put Ubound(MyArrayVar). Everything is fine. But if I reference the array variable from the form itself, I get Error #9, subscript out of range, and I believe this means that my array variable has been killed.
Likewise, if I comment out the line that calls MakeForm from "1.", and comment out the message box there, and then I go and create my own new form and put on it a command button that says msgbox ubound(MyArrayVar), everything is fine.
If I let the MakeForm procedure run through as normal, then go and create my own form, using msgbox ubound(MyArrayVar), then I get the Error #9 again.
So the short version of the long story is:
I am confident that by declaring a Public variable in the declarations section of a module, that you will have a variable available for use as long as the application is running, regardless what other procedures are run between assigning a value to the variable and calling the variable. Is this correct do you think?
So how is it, possibly, that my array variable is getting wiped out here, when, at the end of my Call MakeForm statement, and just before the final End Sub, it is still available to other class modules, etc.??
Sorry for the long note. As you can see, I've spent a lot of time on this. Any help you can provide is very much appreciated.
Thanking you in advance.
-Mike