It's only a guess but, you are looping through all the forms and unloading them, so therefore is it trying to unload the mdi parent form again.
Try something like :

for each frm in forms
if frm.name <> "mdiParent" then unload frm
next frm