Make Folder Directories

  • Thread starter Thread starter dan.cawthorne
  • Start date Start date
D

dan.cawthorne

Hi All,

I was wondering if a could make a directories button from a button
with in a form that also created sub folders.

I did some time ago manage to create a folder with in a Folder, i
can't quite remember the code a used, but

it Created a folder using the [ProjectQ] Field and [ProjectTitle]
Field from a table, from a current record on a form.

and it created a Folder Ie "Q580307 - Sainsbury's Barnstable" the
directorie where the folders are created is "P:\Enquiries Q Folder "

But what i would also like to happen is when I Create the folder

I get this sub Folders Created as well:

Estimating
Health And Safty
Handover
Cost Sheets
O&M Manuals
Site Photos

How do i Code this?

Any Help would be appreciated.

Regards


Dan Cawthorne
 
Hi All,

I was wondering if a could make a directories button from a button
with in a form that also created sub folders.

I did some time ago manage to create a folder with in a Folder, i
can't quite remember the code a used, but

it Created a folder using the [ProjectQ] Field and [ProjectTitle]
Field from a table, from a current record on a form.

and it created a Folder Ie "Q580307 - Sainsbury's Barnstable" the
directorie where the folders are created is "P:\Enquiries Q Folder "

But what i would also like to happen is when I Create the folder

I get this sub Folders Created as well:

Estimating
Health And Safty
Handover
Cost Sheets
O&M Manuals
Site Photos

How do i Code this?

Any Help would be appreciated.

Regards

Dan Cawthorne

Also I Cant Understand why this code dose not work

MkDir P:\Enquirys Q Folder\ & Me.[ProjectQNo] & "_" & Me.
[ProjectTitle]

I get a Compile Error

Expected Line Number, or Label or Statement or End of Statement.
 
Hi All,

I was wondering if a could make a directories button from a button
with in a form that also created sub folders.

I did some time ago manage to create a folder with in a Folder, i
can't quite remember the code a used, but

it Created a folder using the [ProjectQ] Field and [ProjectTitle]
Field from a table, from a current record on a form.

and it created a Folder Ie "Q580307 - Sainsbury's Barnstable" the
directorie where the folders are created is "P:\Enquiries Q Folder "

But what i would also like to happen is when I Create the folder

I get this sub Folders Created as well:

Estimating
Health And Safty
Handover
Cost Sheets
O&M Manuals
Site Photos

How do i Code this?

Any Help would be appreciated.

Regards


Dan Cawthorne

Paste these two functions into a standard module:

''' CODE START '''
Public Function IsPath(ByVal Path As String) As Boolean
' Returns True if path exists
IsPath = (Len(Dir$(Path, vbDirectory)) > 0)
End Function

Public Function CreatePath(ByVal pstrPath As String) As Long
' Creates complete path pstrPath if it doesn't already exist
' Returns 0 for success, or error number
' Accepts 'normal' (DOS) or UNC paths
'
' eg: ErrNum = CreatePath("c:\access\newpath")
'
' or: ErrNum = CreatePath("\\server\share\access\newpath")

Const SLASH As String = "\"
Const TWOSLASH As String = "\\"
'
Dim i As Integer, j As Integer
Dim strBuild As String
'
On Error GoTo CreatePath_Err
'
' Bail out now if path already exists
If Len(Dir$(pstrPath, vbDirectory)) > 0 Then Exit Function
'Ensure path is terminated properly
If Right$(pstrPath, 1) <> SLASH Then pstrPath = pstrPath & SLASH
'
'Find starting point
If InStr(1, pstrPath, ":") = 2 Then
'Normal path
j = 4
ElseIf InStr(1, pstrPath, TWOSLASH) = 1 Then
'UNC path
j = InStr(3, pstrPath, SLASH) + 1 'Skip server name
j = InStr(j, pstrPath, SLASH) + 1 'Skip share name
Else
'Illegal path - return 'Path/file access error'
Err.Raise 75
End If
'Start accumulating
strBuild = Left$(pstrPath, j - 1)
'
Do
i = InStr(j, pstrPath, SLASH)
'Bail out if no more slashes
If i = 0 Then Exit Do
'Accumulate next part of path
strBuild = strBuild & Mid$(pstrPath, j, i - j)
'If it doesn't already exist
If Not IsPath(strBuild) Then
'Create it
MkDir strBuild
End If
strBuild = strBuild & SLASH
j = i + 1
Loop

CreatePath_Exit:
Exit Function

CreatePath_Err:
'Return error
CreatePath = Err.Number
Resume CreatePath_Exit

End Function
''' CODE END '''

To use, simply pass the complete path to be created to the CreatePath
function:

Path = "C:\MyFirstFolder\MyFirstSubfolder"
ReturnVal = CreatePath(Path)

If MyFirstFolder already exists then just MyFirstSubfolder will be created.
If none of the above exist then the two folders will be created.
 
Also I Cant Understand why this code dose not work

MkDir P:\Enquirys Q Folder\ & Me.[ProjectQNo] & "_" & Me.
[ProjectTitle]

I get a Compile Error

Expected Line Number, or Label or Statement or End of Statement.

I think Stuart's answered your original question. The reason you're getting
an error with the code above is that you haven't put the name of the
existing folder in quotes:

MkDir "P:\Enquirys Q Folder\" & Me.[ProjectQNo] & "_" & Me.[ProjectTitle]
 
Back
Top