cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

API MEGA : Error in code to add an application into a library

JLRocchisani
Contributor

Hello,

Here is a Excel VBA macro below in order to add an application and adding it into a library (Bibliothèque).

I encountered a problem in the code compilation (see the bold line in the source code below).

I tried a lot of syntax cases without success.

Is someone could help me (for instance a sample of coding that works in VBA)?

Thanks in advance.

 

 

My code below and the error message

 

' Creation d'une nouvelle application

Function AddAppUti(oAppName As String, oBibLoc As MegaObject, oMegaRoot As MegaRoot) As MegaObject

 

Dim OINUti As MegaObject 'instance
Dim oMyCollection As MegaCollection ' collection

 

Const CentralIBFS As String = ")1NWy6usDXSO" ' Bib central

Select Case Left(oAppName, InStr(oAppName, "-") - 1)

    Case "HARPE", TRANS 'Application catalogue
        ' traitée manuellement
       
        Set AddAppUti = Nothing
       
    Case Else 'Autre application
        ' creation d'une application
       
    Set AddAppUti = oMegaRoot.GetSelection("Select Application Inherited where [Nom court] =""" & oAppName & """").Item(1)
       
        If IsEmpty(AddAppUti.GetID) Then ' création d'une application
       
            Set AddAppUti = oMegaRoot.GetCollection("Application").Create(oAppName)
            ' rattachement bibliothèque
            oBibLoc.GetCollection("Elément contenu").Add AddAppUti.GetID <<< error to the compilation    
            Set OINUti = AddAppUti.GetCollection("Instance d'application (SG) utilisée").Item(1)
            If IsEmpty(OINUti.GetID) Then 'creation d'instance
                Set OINUti = AddAppUti.GetCollection("Instance d'application (SG) utilisée").Add(oAppName)
                ' rattachement bibliothèque
                oBibLoc.GetRoot.GetCollection("Instance d'application (SG)").Add OINUti.GetID
               
   
            End If
        End If
   
End Select

End Function

 

The error message

 

ErrorVBA.jpg

 

2 Replies

Thank you Stephane for your help

 

the second method works !!!

 

here is the final coding.

 

        Set AddAppUti = oMegaRoot.GetSelection("Select Application Inherited where [Nom court] =""" & oAppName & """").Item(1)
       
        If IsEmpty(AddAppUti.GetID) Then ' création d'une application
       
            Set AddAppUti = oMegaRoot.GetCollection("Application").Create(oAppName)
            ' rattachement bibliothèque
            Set AddAppUti = oBibLoc.GetCollection("Elément contenu").Add(AddAppUti.GetID)
   
            Set OinUti = oMegaRoot.GetSelection("Select [Instance d'application (SG)] Inherited Where [Utilisation d'application].[Nom court] =""" & oAppName & """").Item(1)
            If IsEmpty(OinUti.GetID) Then 'creation d'instance
                Set OinUti = oMegaRoot.GetRoot.GetCollection("Instance d'application (SG)").Create(oAppName)
            ' rattachement application utilisée
                Set AddAppUti = OinUti.GetCollection("Utilisation d'application").Add(AddAppUti.GetID)
             ' rattachement bibliothèque
                Set OinUti = oBibLoc.GetCollection("Elément contenu").Add(OinUti.GetID)
  
            End If
        End If

SMAINIL
Super Contributor

Hi,

 

did you try to use insert instead of add?

oBibLoc.GetCollection("Elément contenu").insert AddAppUti

 

or like you did later in your code, try to set the result of the add function to a variable.

dim oTmp as MegaObject

set oTmp = oBibLoc.GetCollection("Elément contenu").Add(AddAppUti)

 

Regards,

Stéphane