Results 1 to 13 of 13
  1. #1
    Lounger
    Join Date
    Jul 2002
    Posts
    27
    Thanks
    0
    Thanked 1 Time in 1 Post

    Project VBA; payrate.delete (Project 2002)

    Does anyone know the proper syntax for the payrate.delete command in VBA? I am trying to automate the deletion of future payrates within the payrates collection for a cost table collection such that I can change them and add new payrates.

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Project VBA; payrate.delete (Project 2002)

    Microsoft Project 2002 Objects (top level of object model)
    > Microsoft Project Objects (Resources) (resource tables)

    Okay, that helps me figure out what you're talking about. <img src=/S/wink.gif border=0 alt=wink width=15 height=15> I'm afraid I haven't loaded the application. What methods do you find in the object browser for the PayRate object or the PayRates collection? The parameters should be listed in the lower pane and/or online help.

  3. #3
    Lounger
    Join Date
    Jul 2002
    Posts
    27
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Project VBA; payrate.delete (Project 2002)

    (Edited by HansV to reduce size of 97 KB screenshot - it caused the page to scroll horizontally)

    The payrate object has a method called delete. The payrate object is a member of the payrates collection (at least that is my understanding). The payrates collection does not have delete method, only add. The payrates collection does not list payrate as one of its objects so I am a little confused.

    I have attached the screen shot that shows the view of the object browser for the Payrate object, but not the payrates collection.

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Project VBA; payrate.delete (Project 2002)

    I don't have Project but what you described is pretty logical given the way MS structures its object models. The Payrates collection doesn't need a delete method. And the Payrate object doesn't need an Add method because you aren't adding anything to it, you create a whole new payrate. You only add a Payrate to the Payrates collection, so that's where the Add method is required. The normal methods for collections are Add and Remove, not Delete, and that sounds like it is being handled behind the scenes when you delete a Payrate. Payrates, as a collection, would not list Payrate as a property because it is a member of the collection, not a method or property of the collection (I know, there's scant difference, but trust me for now). The name of the collection tells you what it contains.
    Charlotte

  5. #5
    Lounger
    Join Date
    Jul 2002
    Posts
    27
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Project VBA; payrate.delete (Project 2002)

    Thank you for the explanation on how collections relate to their objects. It was a great, concise summary and cleared up some thing for me. Remove is not a method listed within the payrates collection.

    To get back to the original question as to the proper syntax for using the payrate.delete method, the following is a portion of my code. I get an " Run Time error 5: Invalid proceedure call or argument" error at the objPR=payrate.delete line.

    Dim objPR as Payrate
    Dim objR as Resource
    Dim objCRT as CostRateTable

    For Each objCRT In objR.CostRateTables
    If objCRT.Name = "A" Then
    For Each objPR In objCRT.PayRates
    objPR.Delete
    End If
    Next objPR
    Next objCRT

  6. #6
    Lounger
    Join Date
    Jul 2002
    Posts
    27
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Project VBA; payrate.delete (Project 2002)

    The attachment may be easier to read as part of this post that shows my sample code I am trying to use. Again, I get an error on line objPR.Delete and I cannot figure out how to delete a payrate.

  7. #7
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Project VBA; payrate.delete (Project 2002)

    I haven't installed Project, but one thing that can trip you up in these For Each loops is that the collection over which you're interating keeps changing. The usual workaround is to use a numeric counter and count backwards like this:

    Dim intCounter as Integer
    Dim objR as Resource
    Dim objCRT as CostRateTable

    For Each objCRT In objR.CostRateTables
    If objCRT.Name = "A" Then
    For intCounter = objCRT.PayRates.Count to 1 Step -1
    objCRT.Payrates(intcounter).Delete
    Next
    End If
    Next objCRT

    This way, the loop counter always refers to an object that you know has not been "renumbered" as a result ot other objects disappearing from the collection.

    Also, your loops are inside out at the bottom: your End If is inside your interior Next loop. That can't be good. <img src=/S/wink.gif border=0 alt=wink width=15 height=15>

  8. #8
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Project VBA; payrate.delete (Project 2002)

    Just because a collection normally has an Add and a Remove method doesn't mean that every collection implements those methods or at least that it exposes them. What exactly is a Payrate object? If it is the equivalent of a field in a table, then you don't want to delete it anyhow, you want to clear its value. Since I don't have Project installed, I can't guess at what might be happening here but the fact that you're getting an error suggests that you can't do what you're trying, or at least not in the way you're trying to do it. At a guess, it looks like you're trying to remove every payrate from a CostRateTable named "A". If that is what you're trying to do, you may need to use your on-line help or documentation to make sure that you're going about it the right way. If you see a delete method in intellisense, that doesn't necessarily mean that it is usable in the context in which you try to use it. <img src=/S/shrug.gif border=0 alt=shrug width=39 height=15>
    Charlotte

  9. #9
    Lounger
    Join Date
    Jul 2002
    Posts
    27
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Project VBA; payrate.delete (Project 2002)

    A payrate object is a set of fields within one cost table that includes an effective date for payrates to change and multiple rate fields for standard rate, overtime rate, etc. If multiple payrate objects have been added to the cost table, then you have rates that can change for each year or timeframe that you add a payrate change. The payrates collection is all the payrate objects that are in one cost table.

    I am looking for any command that can clear out or delete the data that is in the fields for that payrate object. I was hoping the payrate.delete command would work, but I cannot figure out how to use it and do not know of another command that will do what I want.

  10. #10
    Lounger
    Join Date
    Jul 2002
    Posts
    27
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Project VBA; payrate.delete (Project 2002)

    It worked, it worked , it worked. Thank you so much.

  11. #11
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Project VBA; payrate.delete (Project 2002)

    If this is something built into Project, rather than being a custom collection, you might want to ask the question in the Project board. If you do that, you can post a link back to this thread so that Loungers in Project can easily get the background from here and so that everyone knows the question has been asked twice.
    Charlotte

  12. #12
    Lounger
    Join Date
    Jul 2002
    Posts
    27
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Project VBA; payrate.delete (Project 2002)

    The previous thread with jscher2000 gave me the answer. The correct syntax/method was "objCRT.PayRates(intCounter).Delete". Thanks for all the help everyone.

  13. #13
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Project VBA; payrate.delete (Project 2002)

    Hi, I noticed that you got a response on microsoft.public.project.vba today, and the MVP recommends not deleting all the payrates (his method leaves the first one). I don't know the reasoning behind that. If it turns out that deleting all of them causes problems, please post a note for anyone who looks up this thread in the future.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •