moonmonkey
Programmer
Have a look at this very basic function:
Public Function PutFolderContentsInCollection(ByVal strFolder As String, ByRef ColFiles As Collection) As Boolean
On Error GoTo errorhandler
Dim strFileName As String
Dim ColCopyOfOriginal As New Collection
Set ColCopyOfOriginal = ColFiles
strFileName = Dir(strFolder)
Do Until strFileName = ""
ColFiles.Add strFolder & strFileName
strFileName = Dir
Loop
PutFolderContentsInCollection = True
Exit Function
errorhandler:
PutFolderContentsInCollection = False
Set ColFiles = ColCopyOfOriginal
Exit Function
End Function
Basically, before I start adding, I want to make a copy of the original collection, called ColCopyOfOriginal. If the function fails, then the collection ColFiles should get set to ColCopyOfOriginal. However, when I use "Set ColCopyOfOriginal = ColFiles", it seems to LINK the two collections, so when I add to "ColFiles", it adds to "ColCopyOfOriginal" too! Is there a quick way to make a copy of collection "ColFiles" without looping through it all?!
Public Function PutFolderContentsInCollection(ByVal strFolder As String, ByRef ColFiles As Collection) As Boolean
On Error GoTo errorhandler
Dim strFileName As String
Dim ColCopyOfOriginal As New Collection
Set ColCopyOfOriginal = ColFiles
strFileName = Dir(strFolder)
Do Until strFileName = ""
ColFiles.Add strFolder & strFileName
strFileName = Dir
Loop
PutFolderContentsInCollection = True
Exit Function
errorhandler:
PutFolderContentsInCollection = False
Set ColFiles = ColCopyOfOriginal
Exit Function
End Function
Basically, before I start adding, I want to make a copy of the original collection, called ColCopyOfOriginal. If the function fails, then the collection ColFiles should get set to ColCopyOfOriginal. However, when I use "Set ColCopyOfOriginal = ColFiles", it seems to LINK the two collections, so when I add to "ColFiles", it adds to "ColCopyOfOriginal" too! Is there a quick way to make a copy of collection "ColFiles" without looping through it all?!