none
Userform code to add task to ActiveProject in MSProject 2003 RRS feed

  • Question

  • Hi all,

    I'm hoping you can point me in the correct direction.  I'm creating a UserForm to enter tasks into my project - so the user can enter all the additional fields the company would like added in one place (I'm essentially creating a new Task Entry form with the company info added).

    I'm very new to VBA inside of MSProject.  I created my UserForm and now am trying to figure out the code.  I figure I only want it to add the information if the OK button is clicked and throw it away if the Cancel button is clicked.  I figured out how to add the task.name but how do I add the rest of the data, e.g. work, duration, predecessor, text11, outline_code 7, .... 

    Thanks in advance!!!!

    So this is what I have so far:

    Private Sub cmdOK_Click()

    Dim txtName As String
    Dim lngWork As Long

    ActiveProject.Tasks.Add (txtName)
    Me.Hide

    End Sub

    Private Sub cmdCancel_Click()
    frmBusOpsData.Hide

    End Sub

    Monday, October 18, 2010 9:53 PM

Answers

  • Hi,

    1. Indeed, if you insert a blank task that means the name you give is blank. Txtname.value gives the content

    2. Activeselection.tasks(1) gives access to the selected task.

    3. Alkl this is release-independent

    PS. Personally I never call a user form directly but I call a sub that shows the user form.

    Tuesday, October 19, 2010 2:23 PM
    Moderator

All replies

  • Hi,

    Here's the trick

    instead of just adding the task

    ActiveProject.Tasks.Add (txtName)

    Complete this statement

    Set NuTask=activeproject.tasks.add(txtname)

    Then you can set

    nutask.duration=

    nutask.work=

    etc.

     

    Tuesday, October 19, 2010 6:33 AM
    Moderator
  • Hi Jan,

    Ok, that code works when I hard code txtname, duration, ...  What I really want it to do is pull it from my UserForm.  I created a UserForm with 2 text boxes.  One I named txtName and one I named lngWork.  However it doesn't work quite as a I expected, the code will add a blank task so I must not be referencing the UserForm data correctly.

    Also, it there a way that if the user calls up my userform while in a row that has data that I can pull that data and display it in my form so the user could edit it versus always adding a new task?

    PS. Not everyone in the company has been upgraded to the most recent release of Project.  Some still have Project 2003 so that is what I'm writing my code (VB 6.5 & Project 2003).

    THANKS!

    Tuesday, October 19, 2010 1:35 PM
  • Hi,

    1. Indeed, if you insert a blank task that means the name you give is blank. Txtname.value gives the content

    2. Activeselection.tasks(1) gives access to the selected task.

    3. Alkl this is release-independent

    PS. Personally I never call a user form directly but I call a sub that shows the user form.

    Tuesday, October 19, 2010 2:23 PM
    Moderator
  • ok that definitely helps.  I'm getting close.  THANKS FOR THE HELP!!!
    Tuesday, October 19, 2010 8:45 PM