Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / February 2006

Tip: Looking for answers? Try searching our database.

Out of memory

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jes - 16 Feb 2006 09:02 GMT
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?
Jezebel - 16 Feb 2006 09:36 GMT
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.

>I have created a template which runs a macro containing a form and some
>code
[quoted text clipped - 11 lines]
>
> How can I avoid getting "Out of memory" errors?
Jes - 16 Feb 2006 13:16 GMT
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
[quoted text clipped - 13 lines]
> are never responsible for their own lifespans. Thus a form should never try
> to destroy itself.
Jezebel - 17 Feb 2006 21:07 GMT
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.

> Hi Jezebel,
>
[quoted text clipped - 49 lines]
>> try
>> to destroy itself.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.