Merging Text Fields using VBA

M

Marc

I grabbed the following snipped from Mr. Dahlgren's website:

For Each mytask In ActiveProject.Tasks
If Not (mytask Is Nothing) Then
mytask.Text12 = mytask.OutlineParent.Text12 & " | " & mytask.Name
End If
Next mytask

VB doesn't like this. It gives an '1101' project undefined error. I'm
thinking that you can't just concatenate the Text12 object that way. ( I
have no problem just setting mytask.Text12 = "taskname" as a test)

Am I correct and if so - how should I concatenate Text12 ?
 
J

Jim Aksel

Perhaps you forgot to dimension the mytask variable.
This works fine:

Public Sub SampleCode()
Dim mytask As Task
For Each mytask In ActiveProject.Tasks
If Not (mytask Is Nothing) Then
mytask.Text12 = mytask.OutlineParent.Text12 & " | " & mytask.Name
End If
Next mytask
End Sub


HTH
--
If this post was helpful, please consider rating it.

Jim Aksel, MVP

Check out my blog for more information:
http://www.msprojectblog.com
 
M

Marc

No, that wasn't it but in pursuing your suggestion I found the answer, so
thanks.

As I mentioned, it was a snippet. I had thought that there was something
with the string concatenation. After you suggested the dimensioning of
variables, I looked at the code again and decided to run the debugger.

I discovered that the concatenate didn't fail the first time, but about 1/2
way through. As such, that alone couldn't be the issue. It was failing, it
turned out, on inordinately long task names that had been cut/pasted in.

Although I'm not sure why the long task names were causing the problem, they
were too long for my purposes anyway, so I edited them down in size and
solved the problem that way, i.e. via workaround.

Thanks again.
 

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