How loop through records and create folders for each record on a server drive

I have a database that contains several records related to properties.  I want to somehow run a function that will create a folder on a server drive for me for each of this properties just by clicking a button on a temporary form.

The schema for the folders on the server will be like:

Master Folder Name (to be named "Properties"
>>>>>City, State (from the property record)
>>>>>>>>>>Property Name (from the Property record)

In other words as an example like this screen shot:

Server folder example
How can this be done?
SteveL13Asked:
Who is Participating?

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

x
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:
what is the name of the table? and the fields on the table?

upload a sample db with the table.
SteveL13Author Commented:
Database sample attached.
Make-Folders.accdb
Rey Obrero (Capricorn1)Commented:
what is the path to the server?
The 7 Worst Nightmares of a Sysadmin

Fear not! To defend your business’ IT systems we’re going to shine a light on the seven most sinister terrors that haunt sysadmins. That way you can be sure there’s nothing in your stack waiting to go bump in the night.

Rey Obrero (Capricorn1)Commented:
First copy this line to the top of a regular module

Option Compare Database
Option Explicit

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

Open in new window



then use this codes in the click event of the button

Private Sub cmdCreateFoldersonServer_Click()
Dim rs As DAO.Recordset, strFolder As String
Set rs = CurrentDb.OpenRecordset("tblProperties")
Do Until rs.EOF
strFolder = "\\ServerName\SharedFolderName\Properties\" & rs!City & "\" & rs!State & "\" & rs!PropertyName & "\"

MakeSureDirectoryPathExists strFolder

rs.MoveNext
Loop
rs.Close
End Sub

Open in new window


change  \\ServerName\SharedFolderName  accordingly



.

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
SteveL13Author Commented:
Absolutely perfect!!!  I did change one line to add the property ID and put the city and state in the folder name...

strFolder = "C:\Properties\" & rs!City & " " & rs!State & "\" & rs!ID & " - " & rs!PropertyName & "\"
SteveL13Author Commented:
Absolutely amazing.  Thank you!
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.