I have created a template which runs a macro containing a form and some code
in a module.
But if Word has (or have had) several instances of a document created from
the template open the user gets a â??out of memoryâ?? error when the macro runs.

If all instances of word are closed the macro runs again and functions
probably.

I figure itâ??s because the form and the module isnâ??t unloaded probably. I
have tried to insert an â??Unload Meâ?? statement in the form instead of hide.
But itâ??s the same.

How can I avoid getting â??Out of memoryâ?? errors?

Re: Out of memory by Jezebel

Jezebel
Thu Feb 16 03:36:46 CST 2006

Almost certainly the problem is that your code isn't cleaning up properly.
Yes you need to unload your forms. Hard to make specific suggestions about
code structure; but better than 'Unload me' within the form is for the
calling code to take care of it, eg ---

Dim pForm as frmMyForm

Set pForm = new frmMyForm
pForm.Show
:

unload pForm
Set pForm = nothing


In other words, treat all forms as objects: instantiate them and destroy
them as needed. A basic prinicple of object-oriented coding is that objects
are never responsible for their own lifespans. Thus a form should never try
to destroy itself.



"Jes" <Jes@discussions.microsoft.com> wrote in message
news:BDA13F4D-C55B-4849-A6A8-9712E343CE68@microsoft.com...
>I have created a template which runs a macro containing a form and some
>code
> in a module.
> But if Word has (or have had) several instances of a document created from
> the template open the user gets a "out of memory" error when the macro
> runs.
>
> If all instances of word are closed the macro runs again and functions
> probably.
>
> I figure it's because the form and the module isn't unloaded probably. I
> have tried to insert an "Unload Me" statement in the form instead of hide.
> But it's the same.
>
> How can I avoid getting "Out of memory" errors?
>



Re: Out of memory by Jes

Jes
Thu Feb 16 07:16:28 CST 2006

Hi Jezebel,

Thanks!

Right, is must be my pure garbage collection skills.

I now have the following code:

Dim pForm As UserFormTUSKrav
Private Sub Document_New()
Set pForm = New UserFormTUSKrav
pForm.initUserFormTUSKrav
Unload pForm
Set pForm = Nothing
End Sub

Private Sub Document_Close()
Set pForm = New UserFormTUSKrav
pForm.initUserFormTUSKrav
pForm.saveDoc
Unload pForm
Set pForm = Nothing
End Sub

But I still get the same error message â?? â??out of memoryâ??â?¦ when several
instances of the template has been run.

Any ideas?
/Jes

"Jezebel" skrev:

> Almost certainly the problem is that your code isn't cleaning up properly.
> Yes you need to unload your forms. Hard to make specific suggestions about
> code structure; but better than 'Unload me' within the form is for the
> calling code to take care of it, eg ---
>
> Dim pForm as frmMyForm
>
> Set pForm = new frmMyForm
> pForm.Show
> :
>
> unload pForm
> Set pForm = nothing
>
>
> In other words, treat all forms as objects: instantiate them and destroy
> them as needed. A basic prinicple of object-oriented coding is that objects
> are never responsible for their own lifespans. Thus a form should never try
> to destroy itself.
>


Re: Out of memory by Jezebel

Jezebel
Fri Feb 17 15:07:50 CST 2006

Put a messagebox or debug.print statement in the form's Terminate event, and
check that it really does terminate. (And similarly for any class modules
you may have.) The sorts of things that will form from unloading are
variables that point to objects on the form itself -- such as a variable
containing a reference to a form control.




"Jes" <Jes@discussions.microsoft.com> wrote in message
news:0BFB7C61-4B9F-43EB-8C4E-5CD1AAAF5C50@microsoft.com...
> Hi Jezebel,
>
> Thanks!
>
> Right, is must be my pure garbage collection skills.
>
> I now have the following code:
>
> Dim pForm As UserFormTUSKrav
> Private Sub Document_New()
> Set pForm = New UserFormTUSKrav
> pForm.initUserFormTUSKrav
> Unload pForm
> Set pForm = Nothing
> End Sub
>
> Private Sub Document_Close()
> Set pForm = New UserFormTUSKrav
> pForm.initUserFormTUSKrav
> pForm.saveDoc
> Unload pForm
> Set pForm = Nothing
> End Sub
>
> But I still get the same error message - "out of memory". when several
> instances of the template has been run.
>
> Any ideas?
> /Jes
>
> "Jezebel" skrev:
>
>> Almost certainly the problem is that your code isn't cleaning up
>> properly.
>> Yes you need to unload your forms. Hard to make specific suggestions
>> about
>> code structure; but better than 'Unload me' within the form is for the
>> calling code to take care of it, eg ---
>>
>> Dim pForm as frmMyForm
>>
>> Set pForm = new frmMyForm
>> pForm.Show
>> :
>>
>> unload pForm
>> Set pForm = nothing
>>
>>
>> In other words, treat all forms as objects: instantiate them and destroy
>> them as needed. A basic prinicple of object-oriented coding is that
>> objects
>> are never responsible for their own lifespans. Thus a form should never
>> try
>> to destroy itself.
>>
>