Learn how to use the Access MkDir function with syntax and examples.
The Microsoft Access MkDir statement allows you to create a new folder or directory.
The syntax for the Microsoft Access MkDir statement is:
path is the folder or directory to create.
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:
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.
The MkDir statement can be used in the following versions of Microsoft Access:
In this example, the MkDir statement would create a new directory called Examples under the c:\TOTN directory.
The MkDir statement can be used in VBA code in Microsoft Access. For example:
In this example, the directory called Files would be created under the c:\TOTN\Examples directory.
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.
(scroll to see more)