Error message when macro assigns material resource to a task: "Run-Time Error 1101. The argument value is not valid"

Support for Office 2003 has ended

Microsoft ended support for Office 2003 on April 8, 2014. This change has affected your software updates and security options. Learn what this means for you and how to stay protected.

This article was previously published under Q242723
Symptoms
In Microsoft Project, when you run a Microsoft Visual Basic for Applications macro that assigns a material resource, you may receive the following error message:
Run-time error '1101':

The argument value is not valid.
Cause
This behavior occurs when you run a Visual Basic for Applications macro that uses the Add method to assign a material resource and includes a variable material consumption rate in the Units value, for example, 2/d or 2/wk.

For example, the following macro generates the error described above:
Sub addRes() ActiveProject.Tasks(1).Assignments.Add ResourceID:=1, Units:="2/d"End Sub				
This behavior occurs because the Units argument of the Add method accepts only an integer or decimal value. Other alphanumeric characters are invalid.

Note that if the macro is assigning a work resource rather than a material resource, a percent (%) sign included in the Units value generates the same error.
Workaround
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
To work around this problem, assign the material resource first; then modify the units for the assignment to add the variable material consumption rate.

For example, the following macro assigns a material resource and then changes its units to 2 per day:
Sub addRes() 'Add resource to task. lAssignUID  =  ActiveProject.Tasks(1).Assignments.Add (ResourceID:=1) 'Based on assignment unique ID (UID) returned while adding 'resource, change units for resource. ActiveProject.Tasks(1).Assignments.UniqueID(lAssignUID).Units = "2/d"End Sub				
PRJ2007PRJ2003
Properties

Article ID: 242723 - Last Review: 03/22/2013 22:30:00 - Revision: 6.0

Microsoft Office Project Professional 2007, Microsoft Office Project Standard 2007, Microsoft Office Project Professional 2003, Microsoft Office Project Standard 2003, Microsoft Project Professional 2010, Microsoft Project Standard 2010, Microsoft Project 2013 Professional, Microsoft Project 2013 Standard

  • kbbug kbpending KB242723
Feedback