I have an array of documents, each belonging to a folder, as well as an array of folders, each belonging to a parent folder with the topmost folder&#039;s parent ID = 0.<BR><BR>I&#039;m trying to count the collective number of documents that lie in a particular folder and it&#039;s subfolders. To do this I have to recursively go through the aDocs array and aFolders array, but I am getting a "subscript out of range".<BR><BR>&#039;Call the function...<BR>intFilesInFolder = FilesInFolder(thisID, 0)<BR><BR>&#039;Recursively count no. files in folder & subfolders<BR>Function FilesInFolder(FolderID, intNoFiles)<BR> <BR> &#039;Count docs in this folder<BR> For iRowLoop = 0 to UBound(aDocs, 2)<BR> If CInt(aDocs(doc_folder_id,iRowLoop)) = CInt(FolderID) Then<BR> intNoFiles = intNoFiles + 1<BR> End If<BR> Next<BR> <BR> &#039;Find subfolder ID&#039;s<BR> For iRowLoop = 0 to UBound(aFolders,2)<BR> If Cint(aFolders(folder_parent, iRowLoop)) = Cint(FolderID) Then<BR> FilesInFolder FolderID, intNoFiles<BR> End If<BR> Next<BR> <BR> FilesInFolder = CInt(intNoFiles)<BR>End Function<BR><BR>Can you help me with what is going wrong? Should I be using a SUB or a FUNCTION? Do I need to recursively pass the two arrays as well?.... <BR><BR>Many thanks<BR><BR>