FileSystemObject getting "type mismatch" error

Hello - the Debug.print statements below get what you'd expect, but the "Set fldr..." statement errors out with a "type mismatch" error.
This code used to work!
What's wrong?

Public Function LoopFilesInFolder() As Integer

    Dim fso As New FileSystemObject, fldr As Folder, fyle As File
    Debug.Print fso.GetFolder("C:\RPA\").Files.Count
    Debug.Print fso.GetFolder("C:\RPA\")
    Set fldr = fso.GetFolder("C:\RPA\")
End Function
Mark LaGrangeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
How about ..

With fso

' more code

End With
Mark LaGrangeAuthor Commented:
well, I had to add the "Set fldr = " to the GetFolder()

    With fso
        Set fldr = .GetFolder("C:\RPA\")
    End With

but it still got the "type mismatch" error.

I should mention that this code works fine on my personal laptop (1), but the error is happening on my work pc (2)
(1) 64-bit, W7, Office 360, Reference set for MS Scripting Runtime, C:\Windows\SysWOW64\scrrun.dll)  
(2) 32-bit, W7, Office 2010, Reference set for MS Scripting Runtime, C:\Windows\system32\scrrun.dll)
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
This code used to work!
Do you mean it used to work in this project? Or in a different project?
Active Protection takes the fight to cryptojacking

While there were several headline-grabbing ransomware attacks during in 2017, another big threat started appearing at the same time that didn’t get the same coverage – illicit cryptomining.

DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
Humm ...
I just tested on W7 Access 2010 ... no error.

I just happen to be working on some code right now using FSO ...
Mark LaGrangeAuthor Commented:
Scott - Different project
Joe - yep, it's strange - the Debug.Print's work fine, but the Set of the Folder object variable gets an error
*** wait, I just tried something ***
The MS Scripting ref was at the bottom; I moved it up to right below the Office 14 Object Library, and now it works (at least in the simplified version of the code where I'm just setting the "fldr" variable). I'll go back and try the full code now (looping through the files in the folder).

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
That's how my Ref order is as well ... ie what you just changed it to.

Not sure why that would matter ... (Scott ?) ... but still.
Mark LaGrangeAuthor Commented:
Yes, it works. Moving the Scripting ref up seems to have fixed it.  :-/
Thank you both for your responses.
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
Whatever it takes :-)
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
If reference order resolved your issue, then you should make sure to disambiguate your references - i.e., write "Dim fld As FileSystemObject.Folder" instead of "Dim fld As Folder". If you had another reference "higher" in the reference list that also included the Folder object, VBA would grab that reference instead of the one you intend, and then when you try to set the <unknown>.fldr object to the FileSystemObject.Folder object, VBA would complain, and you'll get your error.
Mark LaGrangeAuthor Commented:
Ok, thanks Scott - I'll make a note of this.
Fabrice LambertConsultingCommented:
Even better, switch to late binding, and kiss bye bye to references troubles.
Mark LaGrangeAuthor Commented:
I just tried juggling the ref's around, and it worked, just a shot in the dark.
I appreciate the responses of the two experts. They have both helped me many times.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.