PDM GetDerivedBOMs issues

I am trying to get the BOM From Assemblies in PDM and i keep getting this error

This is the code i am using. Can someone help me get this to work.

'Option Explicit

Sub test2()

'For EPDM

Dim Vaultapp            As New EdmVault5

Dim EPDMSearch          As IEdmSearch7

Dim EPDMSearchR         As IEdmSearchResult5

Dim EPDMFile            As IEdmFile9

Dim derivedBOMs()       As EdmBomInfo

Dim ThisWB              As String

Dim i                   As Integer

Dim Length              As Integer

'Login to EPDM Vault

    Vaultapp.LoginAuto "_MO_Vault", 0

   

ThisWB = "130009000.SLDASM"

    Set EPDMSearch = Vaultapp.CreateSearch()

            EPDMSearch.FindFiles = True

            EPDMSearch.FindFolders = False

            EPDMSearch.FindHistoricStates = False

            EPDMSearch.Recursive = True

            EPDMSearch.Filename = "%" & ThisWB & "%"

'Get the first file in the EPDM Vault

    Set EPDMSearchR = EPDMSearch.GetFirstResult

                       

    Set EPDMFile = EPDMSearchR

   

    Call EPDMFile.GetDerivedBOMs(derivedBOMs)

   

    Length = derivedBOMs.Length   'This is what the error is highlighting

   

    While i < Length

        id = derivedBOMs(i).mlBomID

    Wend

End Sub

SolidworksApi macros