Why does this throw NilObjectException error?

[code] Dim f1 As FolderItem
Dim f2 As FolderItem

f1 = SpecialFolder.ApplicationData.Child(“afolder”)
f2 = f1.Child(“anotherfolder”)

If Not f1.Exists Then
f1.CreateAsFolder
End If

If f1.Exists Then
f2.CreateAsFolder <-- NilObjectException error
End If[/code]

At the time you assigned f2, f1 may not have existed, so there was no child to get.

  Dim f1 As FolderItem
  Dim f2 As FolderItem
  
  f1 = SpecialFolder.ApplicationData.Child("afolder")
  If Not f1.Exists Then
    f1.CreateAsFolder
  End If

  f2 = f1.Child("anotherfolder")
  If Not f2.Exists Then
    f2.CreateAsFolder  
  End If

Dah, of course lol, numbnuts, time for bed!

Thanks Kem :slight_smile: