KristianDude
Jun 15 2006, 05:16 PM
Hello,
I'm trying to create new folders from Access on a share drive, where the company is suppose to sort records by job numbers. I am trying to put together a form that would automatically create new folders for a new job where the employees will be saving data. For example:
L: drive
The main folder:
Client1
Subfolder:
Job1
Job2
etc...
what could I use in VBA for creating a new file folder???
Alan_G
Jun 15 2006, 05:34 PM
Hi
The VBA is MkDir(path) to create a new directory, so
MkDir "L:\Client1\Job3"
should create a new folder called Job3. You'll need the necessary permissions I'd imagine
Is that what you're looking for?
HTH
Alan
KristianDude
Jun 15 2006, 05:46 PM
It sure is!!! Thanks a bunch!.... you rock for a newb! HAHA
Alan_G
Jun 15 2006, 06:01 PM
Glad it worked - you're very welcome
KristianDude
Jun 15 2006, 08:09 PM
Okay, I just tried this out on a click event. What's wrong with it?... I'm just trying to create the one folder. I want to combine my job number and job name controls to look like this Client1-Job3 to name the folder.I did this:
MkDir :M\(Forms!JobNumber & " -"Forms!JobName)"
What is wrong with it?
KristianDude
Jun 15 2006, 08:28 PM
This works:
MkDir ("M:\Job3")
How do I have it reference the fields on the form I'm worlking on???
cheekybuddha
Jun 16 2006, 05:53 AM
Try:
MkDir "M:\" & Forms!JobNumber & " -" & Forms!JobName
hth:
d
KristianDude
Jun 16 2006, 09:05 AM
It works out great! :-) Would you know what is needed to create a folder in this new folder with a generic name like "office".
MkDir "M:\Forms!OpenNewJob!JobNumber & "-" & Forms!OpenNewJob!JobName \ Office (new subfolder)
KristianDude
Jun 16 2006, 09:15 AM
Got it!! It was easier than I thought!...
added MkDir"M:\"& (forms....etc...) &"\Office"
Thanks so much! You steered me right!....... are you currently serving in Brixton?.....
KristianDude
Jun 16 2006, 09:30 AM
also....I'm using a button-on click event to execute this code and was wondering how to disable the button once it was clicked?
KristianDude
Jun 16 2006, 09:56 AM
I'm sorry for all of the posts.....I am now trying to get a third folder with generic names like"\office"....
So, how do I get the first 2 folders in the path? So far I have the first and last....how do I reference the middle (#2) folder
1)Client
2)JobNumber-JobName
3)Generic folders
MkDir "M:\" & (Forms!OpenNewJob!ClientCompany)
MkDir "M:\" & (Forms!OpenNewJob!ClientCompany) *THEN* (Forms!OpenNewJob!JobNumber & "-" & Forms!OpenNewJob!JobName) & " \ Office"
I don't know how to tie in the middle....???? Any ideas?
cheekybuddha
Jun 16 2006, 12:28 PM
Use a variable to hold the last instance of the path.
CODE
Dim strPath As String
[color="green"]' Make base directory[/color]
strPath = "M:\" & Forms!OpenNewJob!ClientCompany
MkDir strPath
[color="green"]' Make subfolder based on job no. and job name
' Note that you are tacking on to the path already held in the variable[/color]
strPath = strPath & "\Forms!OpenNewJob!JobNumber & "-" & Forms!OpenNewJob!JobName"
MkDir strPath
[color="green"]' Make further sub folders as required[/color]
MkDir strPath & "\Office"
MkDir strPath & "\Next Folder"
MkDir strPath & "\Yet another folder"
yep, I'm in Brixton at the moment - it's sunny, music is playing in the streets and the beautiful girls are wandering around with distractingly few clothes!
Hope all's well in CA!
d
KristianDude
Jun 16 2006, 12:37 PM
Awesome! Thanks for serving man!!! That's so awesome!........ here's another doosy for you!....
My question:
After creating these folders, it is possible that we will be re-using the ClientCompany folder for another job. What can I add in to have it recognize the client folder and add the rest inside? Any solution you have would rock!
cheekybuddha
Jun 16 2006, 12:47 PM
Basically, you can use MkDir to create a folder in a folder that already exists.
So if you need further folders inside, one method would be rest the strPath variable
CODE
Dim strPath As String
' Make base directory
strPath = "M:\" & Forms!OpenNewJob!ClientCompany
MkDir strPath
' Make subfolder based on job no. and job name
' Note that you are tacking on to the path already held in the variable
strPath = strPath & "\Forms!OpenNewJob!JobNumber & "-" & Forms!OpenNewJob!JobName"
MkDir strPath
' Make further sub folders as required
MkDir strPath & "\Office"
MkDir strPath & "\Next Folder"
MkDir strPath & "\Yet another folder"
' Reset strPath back to client folder
strPath = "M:\" & Forms!OpenNewJob!ClientCompany
' Make further sub folders as required
MkDir strPath & "\This Folder"
MkDir strPath & "\That Folder"
Alternatively, make the folders so that they are made in order as you create each level.
hth,
d
cheekybuddha
Jun 16 2006, 12:51 PM
Sorry, I meant:
So if you need further folders inside, one method would be reset the strPath variable
d
KristianDude
Jun 16 2006, 02:17 PM
Awesome!..... I'll be back Monday to let you know how it went!....the server just got shot down... (TI is working on security). Happy early Fathers Day if you are!
KristianDude
Jun 16 2006, 02:45 PM
.....okay,my last post til' Monday.....
sorry to pick at your brain so much cheeky.....
What you gave me looks good.....but I'm still learning VBA and was just wondering how this code will work out if the client folder already exists?.....when the "new job" button is clicked, the user may or may not be creating a new client folder (i.e. ClientCompany) - depending on if it already exists on the server or not. If it does exist, and the code runs to make the same folder, an error message will pop up and the code stops.
Good weekend to ya!
.....all is well here in Cali!.....wind is picking up like crazy though!
cheekybuddha
Jun 16 2006, 08:40 PM
To test whether a directory already exists use the Dir() function in combination with the Len() function and specify the vbDirectory argument.
CODE
Dim strPath As String
' Make base directory
strPath = "M:\" & Forms!OpenNewJob!ClientCompany
If Len(Dir(strPath, vbDirectory) = 0 Then MkDir strPath
' Make subfolder based on job no. and job name
' Note that you are tacking on to the path already held in the variable
strPath = strPath & "\Forms!OpenNewJob!JobNumber & "-" & Forms!OpenNewJob!JobName"
If Len(Dir(strPath, vbDirectory) = 0 Then MkDir strPath
' Make further sub folders as required
If Len(Dir(strPath & "\Office", vbDirectory) = 0 Then MkDir strPath & "\Office"
If Len(Dir(strPath & "\Next Folder", vbDirectory) = 0 Then MkDir strPath & "\Next Folder"
If Len(Dir(strPath & "\Yet another folder", vbDirectory) = 0 Then MkDir strPath & "\Yet another folder"
' etc...
hth,
d
cheekybuddha
Jun 19 2006, 07:45 PM
Hmm...
Looking back at this I've just seen a typo (repeated many times)

If Len(Dir(strPath, vbDirectory) = 0 Then ...
should be:
If Len(Dir(strPath, vbDirectory)
) = 0 Then ...
Adjust code accordingly.
hth,
d
KristianDude
Jun 20 2006, 09:31 AM
YYYYYEEEEEEESSSSSSSSS!!!!!!!That rocks! It works awesome! I don't know how you do it....helping out people like me while you are helping the COUNTRY! You rock man!!!!!! Thanks for helping me through it!

o! o!

o! o!
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please
click here.