[Webinar] Learn how to a build a cloud-first strategyRegister Now


How to capture subfolder names with VB6

Posted on 2007-10-14
Medium Priority
Last Modified: 2012-06-22
I'm trying to create a program that will capture subfolder names in a given folder.  I have the following code:

Option Explicit
Private mfso As Scripting.FileSystemObject

Sub main()
    Dim objFolder As Scripting.Folder
    For Each objFolder In mfso.GetFolder("C:\test").SubFolders
        MsgBox "folder found"
End Sub

Now I know this won't capture the name, but I'm trying to figure out how I want to proceed.  I thought this code could help me find each subfolder that exists in C:\test.  When I run this code, I get the following error:

Run-time error '91':
Object variable or With block variable not set

Does anyone know what I'm doing wrong?
Question by:bpl5000
LVL 93

Accepted Solution

Patrick Matthews earned 1000 total points
ID: 20074720
Hello bpl5000,

You probably forgot to instantiate the FileSystemObject.

Sub main()
    Dim objFolder As Scripting.Folder
    Set mfso = New Scripting.FileSystemObject

    For Each objFolder In mfso.GetFolder("C:\test").SubFolders
        MsgBox "folder found"

    Set objFolder = Nothing
    Set mfso = Nothing

End Sub



Author Comment

ID: 20074772
D'oh!  How could I miss that?
Thanks Patrick!

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month20 days, 11 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question