Create and delete folder using VBA

Posted on 2007-10-02
Last Modified: 2013-11-28
Hi All
I need some code that will create a folder on the C drive after i've done what i needed i need to delete the folder again. I need to do this with VBA from a button on an Access Form.
Thanks in advance
Question by:cErasmus
    LVL 84

    Accepted Solution

    You can use the MkDir to build a folder:

    MkDir "C:\SomeFolder"

    You can use Kill to remove it:

    Kill "C:\SomeFolder"


    Author Comment

    Got the create part done. Just need to be able to delete it now.
    LVL 61

    Expert Comment

      Dim fsys As New Scripting.FileSystemObject
          fsys.CreateFolder "C:\Myfolder"

    'Do your stuff

        fsys.DeleteFolder "C:\Myfolder", True

    Needs tools -> references, check MS scripting runtime
    LVL 61

    Expert Comment

    Posted too late.  LSM posted what you need.
    LVL 84

    Assisted Solution

    by:Scott McDaniel (Microsoft Access MVP - EE MVE )
    Sorry ... got ahead of myself ... you can't remove a Folder using Kill (that's for Files). Use rmdir:

    rmdir "C:\SomeFolder"

    Note that the folder must be empty ...

    Author Comment

    Thanks for all the quick responces

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Access question - SELECT/UPDATE 11 25
    Running Sum Help 31 23
    Access left join query 5 19
    Access Query concatenation 12 23
    This article is a continuation or rather an extension from Cascading Combos ( and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
    In the previous article, Using a Critera Form to Filter Records (, the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
    In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
    In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

    754 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

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now