Create folders on network using Access db (1 Viewer)

sonny

Registered User.
Local time
Yesterday, 21:52
Joined
Mar 2, 2004
Messages
140
Has anyone used Access to create folders on a drive? I have a db where if someone creates a new project I was hoping to have Access create a new project folder on the drive and give it the location to create it and a name based on one field from the form the user just created!
 

bradcccs

Registered User.
Local time
Today, 15:52
Joined
Aug 9, 2001
Messages
461
This has been covered numerous times on this forum.

The search feature is quite powerful, and can save you a lot of abuse from nasty forum members ;)


Just this once . . . .


Code:
mkdir "c:\directoryname"


OR

If you want user input etc:

mkdir "c:\" & me.textboxname
 

sonny

Registered User.
Local time
Yesterday, 21:52
Joined
Mar 2, 2004
Messages
140
I got this to make the 1st folder but cant figure out how to make sub folders to the one I just created. I'll post the sample db if anyone cant lend a hand...
 

Attachments

  • Make folders.zip
    41.3 KB · Views: 132

sonny

Registered User.
Local time
Yesterday, 21:52
Joined
Mar 2, 2004
Messages
140
Sure I searched this site, spent a bunch of time doing so. Thats how was able to get to the point I am now. I dont understand vb very much. Just enough to get me in trouble. The below code works for me when I create the 1st folder but I dont understand how to reference the folder just created in order to create others. And what I have so far may even be done in a better fashion.
Code:
Option Compare Database

Private Sub MakeAFolder_Click()
Dim strDirectoryPath1 As String
Dim strDirectoryPath2 As String
Dim strDirectoryPath3 As String
Dim strDirectoryPath4 As String
strDirectoryPath1 = "C:\working\A\" + CStr(Me.UPC)
strDirectoryPath2 = "C:\working\B\" + CStr(Me.UPC)
strDirectoryPath3 = "C:\working\C\" + CStr(Me.UPC)
strDirectoryPath4 = "C:\working\D\" + CStr(Me.UPC)

If IsNull(Me.type) Then
Select Case MsgBox("You must select a project type before you can create folders!" & vbCr & vbCr & _
            " Click ""YES"" To Go Back And Enter The Required Information.", vbCritical + vbYes)
           Case vbYes
            Me.type.SetFocus
        End Select
      End If
     
  Select Case Me.type
     Case "A"
       If Len(Dir$(strDirectoryPath1 & "\.", vbDirectory)) <> 0 Then
       MsgBox "This project UPC folder already exists, please Explore the drive for the folder that matches C:\working\A\" + CStr(Me.UPC)
     Else
       MkDir (strDirectoryPath1)
       MsgBox "A folder has been created on the network at location C:\working\A\" + CStr(Me.UPC)
       End If
     Case "B"
       If Len(Dir$(strDirectoryPath2 & "\.", vbDirectory)) <> 0 Then
       MsgBox "This project UPC folder already exists, please Explore the drive for the folder that matches C:\working\B\" + CStr(Me.UPC)
       Else
       MkDir (strDirectoryPath2)
       MsgBox "A folder has been created on the network at location C:\working\B\" + CStr(Me.UPC)
       End If
     Case "C"
       If Len(Dir$(strDirectoryPath3 & "\.", vbDirectory)) <> 0 Then
       MsgBox "This project UPC folder already exists, please Explore the drive for the folder that matches C:\working\C\" + CStr(Me.UPC)
       Else
       MkDir (strDirectoryPath3)
       MsgBox "A folder has been created on the network at location C:\working\C\" + CStr(Me.UPC)
       End If
     Case "D"
       If Len(Dir$(strDirectoryPath4 & "\.", vbDirectory)) <> 0 Then
       MsgBox "This project UPC folder already exists, please Explore the drive for the folder that matches C:\working\D\" + CStr(Me.UPC)
       Else
       MkDir (strDirectoryPath4)
       MsgBox "A folder has been created on the network at location C:\working\D\" + CStr(Me.UPC)
     End If
  End Select
End Sub
 

ghudson

Registered User.
Local time
Today, 01:52
Joined
Jun 8, 2002
Messages
6,195
Did you attempt the code in the link I provided?

This should get you close to what you want [using the CreateDirectory function from the link I provided] since I do not know the specifics of your form...

Code:
CreateDirectory ("C:\Working\" & txtType & "\" & txtUPC)
I am guessing that the Type and UPC are the names of the text boxes that hold those values which you want to create a directory for. You should use a naming convention to identify your objects like txtType and txtUPC [txt is the prefix for text boxes].

Code:
Public Sub CreateDirectory(sPath As String)
On Error GoTo DirectoryError
    
    Dim sPathPart As String
    Dim i As Integer
    
    If Right(sPath, 1) <> "\" Then sPath = sPath & "\"
    
    For i = 1 To Len(sPath)
        If Mid(sPath, i, 1) = "\" Then
            sPathPart = Left(sPath, i - 1)
            MkDir sPathPart
        End If
    Next i
    
DirectoryError:
    Resume Next
    
End Sub
The CreateDirectory function will create the directory if it [the string] does not exist and it will not display an error if it does already exist.
 

sonny

Registered User.
Local time
Yesterday, 21:52
Joined
Mar 2, 2004
Messages
140
First off I want to say thanks for your replies thus far.
No, I did'nt try your code, I read it and tried to make sense of it though.
If you don't mind I'd like to spell out what I'm trying to achieve.
On our network drive employees must keep their project files in 2 different folders. These 2 folders are either "Working" or "FairCost". IE; either the project is active or complete. We then have 4 different types of projects. These are based on the customer asking us to do their project.
So, the path where they are to keep the files arent set to just one location.
Right now, the employee navigates to the drive and creates a UPC folder under Y:\Working\ then whichever of the 4 types of customer\then the UPC
Then they have to make between 2 & 10 other folders within the UPC folder.
Only the employee knows which ones he/she would need to create as far as sub folders. As you can imagine this takes time to preform each time a new project starts. And we also have employees who don't understand how to do this. They put their files in the wrong folders ect...

So, when I came across a post that suggested making folders on the fly was easy and possible, it put a big smile on my face thinking how this would make life so much easier for all!

To be honest, I did'nt think I'd be able to provide this with my limited knowledge of writing code. After spending many hours I finally was able to produce the sample db I posted here for further help. My current code is very long. Yours is much smaller, I just don't know how to incorporate it into my needs.

I could stop where I am and call it good enough to be able to atleast create the UPC folder and place it in the correct location, and tell the employees they would still need to make thier own sub folders.

Now, one question is: is the code I posted a bad starting point and or worthless in order to also make sub folders? I don't know.... What is certain is, if I go any further I will need more than a nudge in the right direction....especially since I want the employee to select from check boxes on the form which ones they need...
 

ghudson

Registered User.
Local time
Today, 01:52
Joined
Jun 8, 2002
Messages
6,195
I can not look at your db since I am still using Access 97. No matter how you are storing your values [check boxes, text boxes], you just need to merge the data together into a string and include the \ slash to seperate each sub directory. My example should be enough to show you how to put a string together and use it when you call the CreateDirectory function. That function will create the directories and sub directories if they do not already exist.
Code:
CreateDirectory ("Y:\Working\" & chkType & "\" & chkUPC)
 

sonny

Registered User.
Local time
Yesterday, 21:52
Joined
Mar 2, 2004
Messages
140
Heres what I have so far. It creates the sub folder under UPC but its called "-1" not what folder the name I need it to be.
Code:
Public Sub CreateDirectory(sPath As String)
On Error GoTo DirectoryError
    
    Dim sPathPart As String
    Dim i As Integer
    
    If Right(sPath, 1) <> "\" Then sPath = sPath & "\"
    
    For i = 1 To Len(sPath)
        If Mid(sPath, i, 1) = "\" Then
            sPathPart = Left(sPath, i - 1)
            MkDir sPathPart
        End If
    Next i
    
DirectoryError:
    Resume Next
    
End Sub

Private Sub Command14_Click()
CreateDirectory ("C:\Working\" & Me.type & "\" & Me.UPC & "\" & Me.Check7)
End Sub
Check7 is just a check box on my form, is this why its building a folder called "-1"
I need to have Check7 = Email if I want the folder name to be Email dont I?
 

sonny

Registered User.
Local time
Yesterday, 21:52
Joined
Mar 2, 2004
Messages
140
I converted to 97
 

Attachments

  • MakeFolders97.zip
    26.5 KB · Views: 123

Users who are viewing this thread

Top Bottom