Here is a rundown of what I'm trying to do:
-Pass in a string from a config file that would look something like "Sent
Items, Old Sent Items"
-Split that string by the comma into an array
-If the string is not nothing then drop into a for loop. For j=1 to the
upper bound of the array, the folder variable .Folders.Item property equals
the string in the element of the array. After that, if the folder variable
is nothing then exit the for loop.
Unfortunately, it breaks on the last part and only gives me the very
non-descriptive "The operation failed. An Object could not be found." error.
Here is the code in question:
arrFolders = Split(folder, ",")
oFolder = oNS.Folders.Item(user)
If Not folder Is Nothing Then
For j = 1 To UBound(arrFolders)
oFolder = oFolder.Folders.Item(arrFolders(j))
oItems = oFolder.Items
If folder Is Nothing Then
Exit For
End If
Next
End If
Interestingly, I have a work around, but it would basically be hard coded,
which isn't acceptible. I would basically just have to oFolder =
oFolder.Folders.Item statements with each element hard coded. Why does this
break when all I'm trying to do is pass in a value from an array?
If I take out all the conditionals and loops and just have the directory
only go one level deep it works as well. This code works:
oFolder = oNS.Folders.Item(user)
oFolder = oFolder.Folders.Item(folder)
oItems = oFolder.Items
Where folder = Sent Items and user = the top level directory. Can someone
please explain why it breaks on the array, and better yet...how to fix it?!?