none
Copying resources to file; "The method is not available in this situation" RRS feed

  • Question

  • I have a code to copy resources to a new file, but get Error 1100 on the setresourcefield method. I want to understand what it means and why it happens.

       

    Sub ResCopy()

    For i = 1 To imax
            With Application.Projects(OrigPoolIndex).Resources(i)
                ResName = .Name
                ResRate = .StandardRate
                ResOTRate = .OvertimeRate
                ResCal = .BaseCalendar
                ResCode = .Code
                ResMax = .MaxUnits
            End With
            Application.Projects(NewPoolIndex).Resources.Add Name:=ResName

            With Application
                .SetResourceField Field:="Code", value:=ResCode, ResourceID:=i, projectName:=NewPoolName
                .SetResourceField Field:="OverTimeRate", value:=ResOTRate, ResourceID:=i, projectName:=NewPoolName
             End With
        Next i

    End Sub

    Thanks in advance for your help!

    Friday, March 23, 2018 5:24 PM

Answers

  • Andre,

    The reason you are getting the error is because you are attempting to set the Code field for specified resources (i.e. ResourceID) in a file that does not yet have any resources. In addition, in your short code above there is no definition for "NewPoolName" so you should get a compile error before the 1100 error.

    If you want to simply transfer resource data from one file to another why not use the ActiveProject.Resources.Add statement followed by using an indexed statement like ActiveProject.Resources(i).Code = "XXXX" for each resource parameter.

    Hope this helps.

    John

    • Marked as answer by Huismu5 Saturday, March 24, 2018 12:03 PM
    Friday, March 23, 2018 8:01 PM

All replies

  • Andre,

    The reason you are getting the error is because you are attempting to set the Code field for specified resources (i.e. ResourceID) in a file that does not yet have any resources. In addition, in your short code above there is no definition for "NewPoolName" so you should get a compile error before the 1100 error.

    If you want to simply transfer resource data from one file to another why not use the ActiveProject.Resources.Add statement followed by using an indexed statement like ActiveProject.Resources(i).Code = "XXXX" for each resource parameter.

    Hope this helps.

    John

    • Marked as answer by Huismu5 Saturday, March 24, 2018 12:03 PM
    Friday, March 23, 2018 8:01 PM
  • Hi John,

    Thanks again for the help. I copied only the loop to the question to make the code readable. For future reference, find the working code snippet below.

    Sub SetupNewPool()

        Dim intOrigPoolIndex As Integer, intNewPoolIndex As Integer
        Dim i As Integer, imax As Integer
        Dim strResName As String, strResRate As String, strResOTRate As String, strResCal As String, strResCode As String, strResMax As String, strResIni As String
        
        intOrigPoolIndex = ActiveProject.Index
        imax = ActiveProject.ResourceCount
        Application.Projects.Add DisplayProjectInfo:=False Template:="c:\temp.mpp"
        intNewPoolIndex = ActiveProject.Index
       
        For i = 1 To imax
            With Application.Projects(intOrigPoolIndex).Resources(i)
                strResName = .Name
                strResRate = .StandardRate
                strResOTRate = .OvertimeRate
                strResCal = .BaseCalendar
                strResCode = .Code
                strResMax = .MaxUnits * 100
                strResIni = .Initials
            End With
            
            'Add the resource by name to the new file
            Application.Projects(intNewPoolIndex).Resources.Add Name:=strResName
            With Application.Projects(intNewPoolIndex).Resources(i)
                .Code = strResCode
                .MaxUnits = strResMax
                .StandardRate = strResRate
                .OvertimeRate = strResOTRate
                .BaseCalendar = strResCal
                .Initials = strResIni
             End With
        Next i
        
    End Sub

    Saturday, March 24, 2018 12:09 PM
  • Andre,

    You're welcome and thanks for the feedback. I'm glad you got it working.

    John

    Saturday, March 24, 2018 3:58 PM