create a folder

How would i check if a folder exists and if it doesn't create it?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rey Obrero (Capricorn1)Commented:
place this code in the top of a regular module

Option Compare Database
Option Explicit
Public Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll" (ByVal lpPath As String) As Long

to check and create a folder if doesn't exists, simply use this code anywhere in your app

MakeSureDirectoryPathExists "c:\Folder1\Folder2\folder3\"

Open in new window

that will create all the folders \Folder1\Folder2\folder3 if they don't exists
vbnetcoderAuthor Commented:
it doesn't seem to like it

vbnetcoderAuthor Commented:
and if i run the form i get an error telling me that this needs to be update to run on 64 bit
Acronis True Image 2019 just released!

Create a reliable backup. Make sure you always have dependable copies of your data so you can restore your entire system or individual files.

Rey Obrero (Capricorn1)Commented:
you don't need the "End Function" line in the code
vbnetcoderAuthor Commented:
it doesn't matter i get an error either way

Also, it tells me that this will not work on 64 bit systems
Rey Obrero (Capricorn1)Commented:
ooh, use the mkdir() function

If Dir(strFullPath, vbDirectory) = vbNullString Then
    'folder doesn't exist, so create it
   mkDir strFullPath


   msgbox "Folder exists"

end if

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rey Obrero (Capricorn1)Commented:
test his one for the 64 bit machine

Public Declare PtrSafe Function MakeSureDirectoryPathExists Lib "imagehlp.dll" (ByVal lpPath As String) As LongLong

Open in new window

Rey Obrero (Capricorn1)Commented:

also test this one

Public Declare PtrSafe Function MakeSureDirectoryPathExists Lib "imagehlp.dll" (ByVal lpPath As String) As Long
vbnetcoderAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.