Access 2013 Form: create a folder

I have a form that uses a auto control number and I would like to have a button that creates a folder on a network share based on the control number.
CMILLERAsked:
Who is Participating?
 
Nick67Connect With a Mentor Commented:
The FileSystemObject is a very useful friend

Dim BuiltPath as String
Dim fs As Object
Set fs = CreateObject("Scripting.FileSystemObject")

BuiltPath = "SomeValidFolderThatTheUserNeedsToCreate"
If fs.FolderExists(BuiltPath) = False Then
    fs.CreateFolder BuiltPath
End If
0
 
Dale FyeCommented:
take a look at the mkDir command.

The user doing this will have to have write permissions on the drive and folder where they are trying to create the new directory.
0
 
CMILLERAuthor Commented:
nick67,

is there a way to have the folder created based on the form control number?
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
Dale FyeCommented:
Provide a little more info please.
0
 
Nick67Commented:
is there a way to have the folder created based on the form control number?
Sure
BuiltPath = "SomeValidFolderThatTheUserNeedsToCreate"
Any way that you can conceive of to build a valid Windows path that the user can create will get built

BuiltPath = "c:\temp\" & me.SomeControlNumber.Value

or anything else is just fine
0
 
CMILLERAuthor Commented:
Still not sure if I explained the control number correctly because I dont see it in your programing.

The table's first field is "Control Number" and a data type of "Autonumber"

So, in the form the "Control Number" is created automatically and thats the number that I want a folder created.
0
 
Nick67Commented:
I had assumed that the control number would come from some control on the form
Hence
me.SomeControlNumber.Value

SomeControlNumber being the name of a control bound to your table's "Control Number" field
(PS, if this project is at the beginning, do yourself a favor... take the spaces out of the field names
Otherwise you will forever have to refer to SomeTable.[Some FieldName] instead of SomeTable.SomeFieldName)
0
 
CMILLERAuthor Commented:
Hi,

I have the build path working but I am not understanding how to write the adding of the control number.

here is what I have.

****************************************************************
Option Compare Database
Option Explicit

Function HROCUSTCALLLOGCREATEFOLDER()

Dim BuiltPath As String
Dim fs As Object
Set fs = CreateObject("Scripting.FileSystemObject")

 BuiltPath = "\\path\folder1\" & me.[Control Number]
 If fs.FolderExists(BuiltPath) = False Then
     fs.CreateFolder BuiltPath
 End If
MsgBox "Folder Created!"
End Function
****************************************************************
0
 
Nick67Commented:
Here's a working sample
The hardcoded part of the path MUST exist.
Only that last folder in the path can be created
Doesn't mean you couldn't do that recursively, but you can't create 14

c:\temp\WhereIWantStuffToGo\14

Until WhereIWantStuffToGo exists
ControlNumber.mdb
0
 
CMILLERAuthor Commented:
Yes, I understand the path.

I downloaded your example and its not quite working like I envisioned.

can you modify the code so that there is one text box not tied to anything and have the cmd button create a folder based on what is entered into the text box?

you can leave the hardcoded path in there and I will change that.

Thanks.
0
 
CMILLERAuthor Commented:
what I mean by text box not tied to anything is not tied to the control number in the table.
0
 
Nick67Commented:
This is the driver

 BuiltPath = "\\path\folder1\" & me.[Control Number]

so,  BuiltPath = "\\path\folder1\" & me.[The Name of Some Unbound Textbox on the Form]. Value

You cannot put an unbound textbox on the detail section of a continuous form, so it's in the header
And, if the user is inputting the number, you now will need to check for uniqueness if that matters to you
ControlNumber-v1.mdb
0
 
CMILLERAuthor Commented:
Hi, I am still having an issue with creating the folder. I will upload a an mdb with just the form and table to see if we can get it to work.

Thanks.
0
 
CMILLERAuthor Commented:
ok, got it working. it wasnt in the header.

What do I add to the code to clear the text box after the folder has been created?
0
 
Nick67Commented:
You are creating a folder with

If fs.FolderExists(BuiltPath) = False Then
    fs.CreateFolder BuiltPath
else
   Msgbox "That folder exists!"
    Exit sub

End If


so, after, check if it exists, and make the textbox value "" if it does
If fs.FolderExists(BuiltPath) = true Then
    Me.The_Name_of_Some_Unbound_Textbox_on_the_Form.Value = ""
End If
0
 
CMILLERAuthor Commented:
THANKS!
0
All Courses

From novice to tech pro — start learning today.