Another "What's wrong with this code?"...

L

lamby74

I really appreciate any suggestions anyone may have. I think I have looked
at it too many times to decipher what I am doing wrong.

The goal of this macro is to automate entry of predecessors and lag time.
I want it to ask the user what the predecessor is, what the lag time is, and
to input the information into task information.

Here is my code:

Sub TWEAKLag_Lead()
Dim getpredecessor As Integer
Dim getlag As Single
Dim t As Task
getpredecessor = InputBox("Enter predecessor.")
getlag = InputBox("Enter Lag Time (+) or Lead Time (-)")
SelectRow Row:=0
SetTaskField Field:="Predecessors", Value:="getpredecessor,SS,getlag,w",
AllSelectedTasks:=True
End Sub


When I run this macro, there are no errors, but all it does is correctly
input the predecessor. it won't change SS, FS, etc, OR lag time.
 
J

JackD

Doesn't look like you have a correctly formed string. Particularly the part
that says SS and w without quotations.

try adding this:

dim myString as string
dim getlag as string 'you need it to be text not an integer
myString = cstr(getpredecessor) & "SS" & getlag & "w"
settaskfield.field:="Predecessors", Value:=myString

You can debug it from there.
 
J

JimS

Hi,

From a quick look, the first problem is that you are including the variable
names getpredecessor and getlag within the string that you are trying to set.
You'll need something like
SetTaskField Field:="Predecessors", Value:=getpredecessor & "SS" & getlag &
"w", AllSelectedTasks:=True

JimS
 
J

Jan De Messemaeker

How about (didn't try but should work)

Value= cstr(getpredecessor) & "SS+" & cstr(getlag)

Commas do not create concatenation in VBA!
(You will probably need an if structure to take negatives into account)
 
L

lamby74

Sorry it took me so long to get back to you all - my boss had me on other
projects for a while....

Here is the code that worked for me and resolved this issue. It is a bit of
a compilation of all your suggestions:


Sub TWEAKLag_Lead()
Dim myString As String
Dim getpredecessor As Integer
Dim getlag As Integer
Dim t As Task

getpredecessor = InputBox("Enter predecessor.")
getlag = InputBox("Enter Lag Time (+) or Lead Time (-)")

myString = CStr(getpredecessor) & "SS+" & CStr(getlag) & "w"
SetTaskField field:="Predecessors", Value:=myString, AllSelectedTasks:=True

End Sub

It's awesome! Thanks to all who helped.
 
S

Sylvain Tricot

test

lamby74 said:
Sorry it took me so long to get back to you all - my boss had me on other
projects for a while....

Here is the code that worked for me and resolved this issue. It is a bit of
a compilation of all your suggestions:


Sub TWEAKLag_Lead()
Dim myString As String
Dim getpredecessor As Integer
Dim getlag As Integer
Dim t As Task

getpredecessor = InputBox("Enter predecessor.")
getlag = InputBox("Enter Lag Time (+) or Lead Time (-)")

myString = CStr(getpredecessor) & "SS+" & CStr(getlag) & "w"
SetTaskField field:="Predecessors", Value:=myString, AllSelectedTasks:=True

End Sub

It's awesome! Thanks to all who helped.
 

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