VBA - Copy EnterpriseNumber2 to EnterpriseNumber39: Errors in Macro

T

TroyS

I'm working on a vba solution to copy EnterpriseNumber2 (task level) to
another EnterpriseNumber39 (task level) (for example...there is more to this
than that, but this is the 1st step)

EnterpriseNumber2 is a counter (a 1 or a 0) based on a text field. If a
particular value in the text field is true, then 1, else 0.

I can copy the values from EnterpriseNumber2 value to say a Number3 field.
But if i try to copy the EnterpriseNumber2 value to an EnterpriseNumber3
(task level) field, i get an error in my macro.

Below are the 2 sample macros. 1 works, 1 does not. Why can't i copy from a
Task EnterpriseNumber field to another Task EnterpriseNumber field?

The error is:
Run Time Error '1101'
The Argument is not valid

When i select debug, the editor goes to the line where i assign/copy the
value in EnterpriseNumber2 to EnterpriseNumber39....

Sample Macro that does not work:
Sub Testing()

Dim T As Task ' Task object used in For Each loop

For Each T In ActiveProject.Tasks
If T Is Nothing Then
GoTo Line1
Else
T.EnterpriseNumber39 = T.EnterpriseNumber2
End If
Line1:
Next T

Sample Macro that does work:

Sub Testing()

Dim T As Task ' Task object used in For Each loop

For Each T In ActiveProject.Tasks
If T Is Nothing Then
GoTo Line1
Else
T.Number1 = T.EnterpriseNumber2
End If
Line1:
Next T
 
J

John

TroyS said:
I'm working on a vba solution to copy EnterpriseNumber2 (task level) to
another EnterpriseNumber39 (task level) (for example...there is more to this
than that, but this is the 1st step)

EnterpriseNumber2 is a counter (a 1 or a 0) based on a text field. If a
particular value in the text field is true, then 1, else 0.

I can copy the values from EnterpriseNumber2 value to say a Number3 field.
But if i try to copy the EnterpriseNumber2 value to an EnterpriseNumber3
(task level) field, i get an error in my macro.

Below are the 2 sample macros. 1 works, 1 does not. Why can't i copy from a
Task EnterpriseNumber field to another Task EnterpriseNumber field?

The error is:
Run Time Error '1101'
The Argument is not valid

When i select debug, the editor goes to the line where i assign/copy the
value in EnterpriseNumber2 to EnterpriseNumber39....

Sample Macro that does not work:
Sub Testing()

Dim T As Task ' Task object used in For Each loop

For Each T In ActiveProject.Tasks
If T Is Nothing Then
GoTo Line1
Else
T.EnterpriseNumber39 = T.EnterpriseNumber2
End If
Line1:
Next T

Sample Macro that does work:

Sub Testing()

Dim T As Task ' Task object used in For Each loop

For Each T In ActiveProject.Tasks
If T Is Nothing Then
GoTo Line1
Else
T.Number1 = T.EnterpriseNumber2
End If
Line1:
Next T
Troy,
There is nothing inherently wrong with your code (although it is overly
complex - see my reply to your more recent post). Therefore the problem
must be related to how you are setting up the counter value for
EnterpriseNumber2. Since you indicate it is based on a text field, I
suspect you are running into an error because EnterpriseNumbers are
"Double" data types (numeric) while text fields are normally "string"
data types (unless a conversion is used). This is demonstrated by the
fact that your second macro does work - both properties (i.e. Number1
and EnterpriseNumber1) are numeric.

Hope this helps.
John
Project MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top