PRJ41: "Out Of Memory" Adding Task or Resource in Macro (136880)



The information in this article applies to:

  • Microsoft Project for Windows 95 4.1

This article was previously published under Q136880

SYMPTOMS

In Microsoft Project, when you use the Add method in a macro to add a task or resource to your project, you may receive the following error messages
Out of memory or system resources
followed by:
Run-time error '7':
Out of memory.
Additionally, when you run a Visual Basic macro in another program and you use OLE Automation to add a task or resource to a project in Microsoft Project, you may receive the error messages described above.

CAUSE

This problem occurs if you use the Add method of the Tasks collection, or the Resource collection, without specifying a name argument.

For example, if you run the following macro in Microsoft Project, you receive these error messages:
   Sub Test()
      Projects(1).Tasks.Add
   End Sub
				
Although the Help topic for the Add method indicates that this argument is required, it also states that by default, the name argument is Empty.

In Microsoft Project version 4.0, you can add a task or resource using the Add method without specifying a name argument. In this case, a task or resource is added without a task name or resource name.

RESOLUTION

To avoid receiving an "out of memory" error message when you add a task to a project using a macro, include a value for the name argument, even if it is empty as in the following examples:

In Microsoft Project

   Sub Test()
      ' Add task "Task1"
      Projects(1).Tasks.Add "Task1"
   End Sub
				

-or-

   Sub Test()
      ' Add blank task
      Projects(1).Tasks.Add ""
   End Sub
				

Using OLE Automation

Sub Test()

   Dim x As Object, y As Object
   Set x = GetObject("", "MSProject.Application")
   x.FileNew
   Set y = x.Projects(1).Tasks.Add ""
 
End Sub
				

STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

Note that when you run a Visual Basic macro in another program and you access Microsoft Project as an OLE Automation object, if you receive the "Run-time error '7':" error message as described above, the error message may contain question mark characters such as "?4????" instead of the "out of memory" text.

For additional information, please see the following article in the Microsoft Knowledge Base:

136881 PRJ4: OLE Automation Run-Time Error Message Contains Question Marks

REFERENCES

For more information about using the Add method to add a task or resource in Microsoft Project, click the Index tab in Microsoft Project Help, type the following text

add

double-click the selected text, and then double click "add method" to go to the "Add Method" topic.

Modification Type:MinorLast Reviewed:10/11/2006
Keywords:kbbug kbcode kberrmsg kbpending kbprogramming KB136880