totn Access Functions

MS Access: MkDir Statement

This MSAccess tutorial explains how to use the Access MkDir function with syntax and examples.

Description

The Microsoft Access MkDir statement allows you to create a new folder or directory.

Syntax

The syntax for the MkDir statement in MS Access is:

MkDir path

Parameters or Arguments

path
The folder or directory to create.

Returns

The MkDir statement does not return a value, but rather creates a new folder or directory.
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.

Applies To

The MkDir statement can be used in the following versions of Microsoft Access:

  • Access 2019, Access 2016, Access 2013, Access 2010, Access 2007, Access 2003, Access XP, Access 2000

Example

Let's look at how to use the MkDir function in MS Access:

MkDir "c:\TOTN\Examples"

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

Example in VBA Code

The MkDir statement can be used in VBA code in Microsoft Access.

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.