Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Access 2013 Form: create a folder

Posted on 2015-02-20
16
Medium Priority
?
115 Views
Last Modified: 2015-03-24
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.
0
Comment
Question by:CMILLER
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 6
  • 2
16 Comments
 
LVL 48

Expert Comment

by:Dale Fye
ID: 40621875
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
 
LVL 26

Accepted Solution

by:
Nick67 earned 2000 total points
ID: 40621914
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
 

Author Comment

by:CMILLER
ID: 40626196
nick67,

is there a way to have the folder created based on the form control number?
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
LVL 48

Expert Comment

by:Dale Fye
ID: 40626204
Provide a little more info please.
0
 
LVL 26

Expert Comment

by:Nick67
ID: 40626222
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
 

Author Comment

by:CMILLER
ID: 40640554
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
 
LVL 26

Expert Comment

by:Nick67
ID: 40640739
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
 

Author Comment

by:CMILLER
ID: 40650888
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
 
LVL 26

Expert Comment

by:Nick67
ID: 40651094
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
 

Author Comment

by:CMILLER
ID: 40674468
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
 

Author Comment

by:CMILLER
ID: 40674474
what I mean by text box not tied to anything is not tied to the control number in the table.
0
 
LVL 26

Expert Comment

by:Nick67
ID: 40674584
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
 

Author Comment

by:CMILLER
ID: 40683480
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
 

Author Comment

by:CMILLER
ID: 40685663
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
 
LVL 26

Expert Comment

by:Nick67
ID: 40685674
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
 

Author Comment

by:CMILLER
ID: 40685764
THANKS!
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question