Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Folder won't delete - type mismatch

Status
Not open for further replies.

genomon

Programmer
Aug 20, 2001
2,449
US
Code:
Dim fso As Scripting.FileSystemObject
Dim fol As Scripting.Folder
Dim fdr As Scripting.Folder
Dim fil As Scripting.File
Dim flc As Scripting.Folders
Const conInputDirectory As String = "G:\OUT\EmailTest\"

    Set fso = CreateObject("Scripting.FileSystemObject")
    Set fol = fso.GetFolder(conInputDirectory)
    Set flc = fol.SubFolders

    For Each fdr In flc
        fdr.Delete
    Next fdr

    Set fso = Nothing
    Set fol = Nothing
    Set flc = Nothing

The above code works for the mapped drive G:, but fails with error 13 - type mismatch for local drive C:\OUT\EmailTest\, with or without the final backslash character; the path exists exactly as used in the GetFolder method. I get the same error when I try fso.DeleteFile, and combinations of Kill/RmDir. Using XP SP2 with Access XP (2002 - not by choice). I have full admin rights to my local and mapped drives. Code is called in the same sub for both addresses by a command button click event.
Anything glaringly obvious I'm missing? Help......


[banghead] [curse]

"Time flies like an arrow; fruit flies like a banana."
 
I ran it this way in Access 2007

Code:
Dim fso
Dim fol
Dim fdr
Dim fil
Dim flc
Const conInputDirectory As String = "C:\Program Files\"

    Set fso = CreateObject("Scripting.FileSystemObject")
    Set fol = fso.GetFolder(conInputDirectory)
    Set flc = fol.SubFolders

    For Each fdr In flc
        Debug.Print fdr.Name
    Next fdr

    Set fso = Nothing
    Set fol = Nothing
    Set flc = Nothing
and it ran fine (I just debug.print(ed)the folder names instead of deleting stuff0. I got a user defined name error when trying to run your Dim statements as they were.
Not sure what the problem is but wanted you to know someone looked at it.

Paul
 
Thanks for the second set of eyes! The error may have been caused by a missing reference to the Microsoft Scripting Runtime library. I'll keep the votive candles lit here...

"Time flies like an arrow; fruit flies like a banana."
 
Paul - user type error is definitely missing library reference. And now....... for idiot of the year. Envelope please..... Surprise. It's me.
Code:
Dim flc As Scripting.Folders

Works fine. Somehow I left the "s" off "folders" in my test environment. Had I used late binding as in Paul's example, there would have been no problems (let's not make this a thread of why late binding is a very bad idea), but because I used early binding and explicitly referenced the Scripting library, the "folder" had to be "folders".
Sorry for the waste of time - I'll go slap myself now...

[poke]


"Time flies like an arrow; fruit flies like a banana."
 
Glad you got it. I assumed it was a missing library on my part, but didn't spend anytime trying to find the correct one. They only recently upgraded me to 2007 and I'm still trying to get around the new menus (which I personally hate). I won't tell you how long it took me to find out how to open a new module.
I wasn't keeping the code except to test your's so late binding wasn't going to eat up any of my resourses.

Paul
 
It gets weirder. I'm back to the original problem, but the weirdness is that the code seems to only fail intermittently, and only on our new Dell desktop PCs. I'm looking into conflicts with the new Norton Endpoint AV software, and maybe corrupt library references. Copied code into ACC 2K and works the same - OK on my older Dell laptop, but spotty on the new Optiplex desktop PCs. Last resort may be to disregard my training and let VBA worry about type matching as you did in your example. Gotta love the mystery, not to mention the job security. Thanks again!
[cheers]




"Time flies like an arrow; fruit flies like a banana."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top