Home Privacy Policy Feedback Link to us Site Map

Access: MkDir Statement


In Access, the MkDir statement allows you to create a new folder or directory.

The syntax for the MkDir function is:

MkDir path

path is the folder or directory to create.


Note:

If path is a complex directory structure, the high-level directories must already exist or the MkDir statement will raise an error.

For example, if you executed the following code:

MkDir "c:\Test\Access"

The c:\Test directory must already exist. The MkDir statement will only attempt to create the Access directory under the c:\Test directory. It will not create the c:\Test directory itself.


For example:

MkDir "c:\TOTN\Examples"

In this example, the MkDir statement would create a new directory called Examples under the c:\TOTN directory.


VBA Code

The MkDir function can be used in VBA code. For example:

MkDir "c:\TOTN\Examples\Files"

In this example, the directory called Files would be created under the c:\TOTN\Examples directory.


Frequently Asked Questions


Question:  I'm not sure if a particular directory exists already. If it doesn't exist, I'd like to create it using VBA code. How can I do this?

Answer:  You can test to see if a directory exists using the VBA code below:

If Len(Dir("c:\TOTN\Examples", vbDirectory)) = 0 Then
    MkDir "c:\TOTN\Examples"
End If

In this example, the code would first check to see if the c:\TOTN\Examples directory exists. If it doesn't exist, the MkDir statement would create a new directory called Examples under the c:\TOTN directory.