Creating Folders From Access

D

dan.cawthorne

Hi All,

Ive managed to create a command button that creates a one level entry
folder based on 2 filed on my table "ProjectQNo" and "ProjectTitle"
and creates the folder where i want it.

this is code i've used

On Error GoTo PROC_ERR

MkDir "P:\QUOTATIONS\" & Me.[ProjectQNo] & " - " & Me.[ProjectTitle]
DoCmd.OpenForm "frm_MakefolderSuccesful"

PROC_EXIT:
Exit Sub
PROC_ERR:
If err.Number = 2101 Then
'take whatever action is appropraite
Else
'perhaps display error message
End If

But I Would Also like to happen is it to create sub folders to, such
as Estimate, Submission and Tender Info

How do i change the code to suit this?

secondly the more complex question is their away i can create a table
that ms access stores the new folder location onces its created the
folder so i can have command button to open that top level folder?
 
D

Damon Heron

Here is one way of doing it.
Command Click....
Dim myPath As String
myPath = "P:\QUOTATIONS\" & Me.[ProjectQNo] & " - " & Me.[ProjectTitle]
MkDir myPath
MkDir myPath & "\Estimate"
MkDir myPath & "\Submission"
etc......

Damon
 
D

Dirk Goldgar

(re-posting, since my original reply hasn't appeared)

Hi All,

Ive managed to create a command button that creates a one level entry
folder based on 2 filed on my table "ProjectQNo" and "ProjectTitle"
and creates the folder where i want it.

this is code i've used

On Error GoTo PROC_ERR

MkDir "P:\QUOTATIONS\" & Me.[ProjectQNo] & " - " & Me.[ProjectTitle]
DoCmd.OpenForm "frm_MakefolderSuccesful"

PROC_EXIT:
Exit Sub
PROC_ERR:
If err.Number = 2101 Then
'take whatever action is appropraite
Else
'perhaps display error message
End If

But I Would Also like to happen is it to create sub folders to, such
as Estimate, Submission and Tender Info

How do i change the code to suit this?

Here's a function that makes an entire folder path, creating any
higher-level folders that don't already exist:

'----- start of code -----
Function MakeFolderPath(PathToMake As String) As Long

' Given a complete or relative positional path of which some folders
' may not exist, create the complete path including any missing folders.

On Error GoTo Err_MakeFolderPath

Dim strFolders() As String
Dim strPath As String
Dim intX As Integer

If Len(PathToMake) = 0 Then
Err.Raise 5
End If

If Right$(PathToMake, 1) = "\" Then
strPath = Left$(PathToMake, Len(PathToMake) - 1)
Else
strPath = PathToMake
End If

strFolders = Split(strPath, "\")

strPath = vbNullString

For intX = LBound(strFolders) To UBound(strFolders)

If intX = LBound(strFolders) Then
strPath = strFolders(intX)
Else
strPath = strPath & "\" & strFolders(intX)
End If

If Len(Dir(strPath, vbDirectory)) = 0 Then
MkDir strPath
End If

Next intX

MakeFolderPath = 0

Exit_MakeFolderPath:
Exit Function

Err_MakeFolderPath:
MakeFolderPath = Err.Number
MsgBox "Unable to create folder '" & strPath & "'" & vbCr & vbCr & _
"Error " & Err.Number & ": " & Err.Description, _
vbExclamation, "Can't Make Folder"
Resume Exit_MakeFolderPath

End Function
'----- end of code -----

secondly the more complex question is their away i can create a table
that ms access stores the new folder location onces its created the
folder so i can have command button to open that top level folder?

I'm not sure what you have in mind. Of course you can store the folder path
in a table -- this is a database, after all -- but the specific details of
what table, what record, what field, and so on, are all up to you. You
would probably use an inline SQL append or update query to to the actual
insertion.

When you say that you want to "open that top level folder", do you mean that
you want to open the folder in an Explorer window? If so, you can do it via
the FollowHyperlink method; for example,

Application.FollowHyperlink "P:\QUOTATIONS"

or

Dim strFolderPath As String
strFolderPath = "P:\QUOTATIONS"
Application.FollowHyperlink strFolderPath
 
D

dan.cawthorne

(re-posting, since my original reply hasn't appeared)




Ive managed to create a command button that  creates a one level entry
folder based on 2 filed on my table  "ProjectQNo" and "ProjectTitle"
and creates the folder where i want it.
this is code i've used
On Error GoTo PROC_ERR
MkDir "P:\QUOTATIONS\" & Me.[ProjectQNo] & " - " & Me.[ProjectTitle]
DoCmd.OpenForm "frm_MakefolderSuccesful"
PROC_EXIT:
Exit Sub
PROC_ERR:
If err.Number = 2101 Then
'take whatever action is appropraite
Else
'perhaps display error message
End If
But I Would Also like to happen is it to create sub folders to, such
as Estimate, Submission and Tender Info
How do i change the code to suit this?

Here's a function that makes an entire folder path, creating any
higher-level folders that don't already exist:

'----- start of code -----
Function MakeFolderPath(PathToMake As String) As Long

    ' Given a complete or relative positional path of which some folders
    ' may not exist, create the complete path including any missing folders.

    On Error GoTo Err_MakeFolderPath

    Dim strFolders() As String
    Dim strPath As String
    Dim intX As Integer

    If Len(PathToMake) = 0 Then
        Err.Raise 5
    End If

    If Right$(PathToMake, 1) = "\" Then
        strPath = Left$(PathToMake, Len(PathToMake) - 1)
    Else
        strPath = PathToMake
    End If

    strFolders = Split(strPath, "\")

    strPath = vbNullString

    For intX = LBound(strFolders) To UBound(strFolders)

        If intX = LBound(strFolders) Then
            strPath = strFolders(intX)
        Else
            strPath = strPath & "\" & strFolders(intX)
        End If

        If Len(Dir(strPath, vbDirectory)) = 0 Then
            MkDir strPath
        End If

    Next intX

    MakeFolderPath = 0

Exit_MakeFolderPath:
    Exit Function

Err_MakeFolderPath:
    MakeFolderPath = Err.Number
    MsgBox "Unable to create folder '" & strPath & "'" & vbCr & vbCr & _
            "Error " & Err.Number & ": " & Err.Description, _
            vbExclamation, "Can't Make Folder"
    Resume Exit_MakeFolderPath

End Function
'----- end of code -----
secondly the more complex question is their away i can create a table
that ms access stores the new folder location onces its created the
folder so i can have command button to open that top level folder?

I'm not sure what you have in mind.  Of course you can store the folderpath
in a table -- this is a database, after all -- but the specific details of
what table, what record, what field, and so on, are all up to you.  You
would probably use an inline SQL append or update query to to the actual
insertion.

When you say that you want to "open that top level folder", do you mean that
you want to open the folder in an Explorer window?  If so, you can do it via
the FollowHyperlink method;  for example,

    Application.FollowHyperlink "P:\QUOTATIONS"

or

    Dim strFolderPath As String
    strFolderPath = "P:\QUOTATIONS"
    Application.FollowHyperlink strFolderPath

Damon thanks for you reply i sure give your code a swirl, seems like
less complex.

Dirk Goldgar

thanks for the reply as well, rather interested in the function call
you have made. i only do basic vb such as docmd. etc getting better
though :)

it does refer to ProjectQNo or ProjectTitle, So How Does it know how
to make a Folder in P:\Quotations\ "Q034408 Ambercombie & Fitch"

do i just put that code in the click event of a button? of do i put it
into a modules?

Second Question, I believe i ment is with in the tblProjects Where
Fields ProjectQNo and ProjectTitle are, i will create a field
"FolderLocation" So the theory behind my idea is once a new project
is created the user can click create new folder it will create a
folder in the P:\Quotation\ for that Project, so everything for that
project like word docs, excel, PDF's and so on (So Answer to your
question it is Explorer type folders) and then what id like to happen
is the in the field "folderlocation" it would store the folder
location which will P:\Quotations\"Project Name" for that record, so
if users search for a project and want to see all related documents,
they could click a button and it will open that folder on server for
that project? which out spending age searching through the server and
going through loads of folders.

Regards

Dan
 
D

dan.cawthorne

(re-posting, since my original reply hasn't appeared)




Ive managed to create a command button that  creates a one level entry
folder based on 2 filed on my table  "ProjectQNo" and "ProjectTitle"
and creates the folder where i want it.
this is code i've used
On Error GoTo PROC_ERR
MkDir "P:\QUOTATIONS\" & Me.[ProjectQNo] & " - " & Me.[ProjectTitle]
DoCmd.OpenForm "frm_MakefolderSuccesful"
PROC_EXIT:
Exit Sub
PROC_ERR:
If err.Number = 2101 Then
'take whatever action is appropraite
Else
'perhaps display error message
End If
But I Would Also like to happen is it to create sub folders to, such
as Estimate, Submission and Tender Info
How do i change the code to suit this?

Here's a function that makes an entire folder path, creating any
higher-level folders that don't already exist:

'----- start of code -----
Function MakeFolderPath(PathToMake As String) As Long

    ' Given a complete or relative positional path of which some folders
    ' may not exist, create the complete path including any missing folders.

    On Error GoTo Err_MakeFolderPath

    Dim strFolders() As String
    Dim strPath As String
    Dim intX As Integer

    If Len(PathToMake) = 0 Then
        Err.Raise 5
    End If

    If Right$(PathToMake, 1) = "\" Then
        strPath = Left$(PathToMake, Len(PathToMake) - 1)
    Else
        strPath = PathToMake
    End If

    strFolders = Split(strPath, "\")

    strPath = vbNullString

    For intX = LBound(strFolders) To UBound(strFolders)

        If intX = LBound(strFolders) Then
            strPath = strFolders(intX)
        Else
            strPath = strPath & "\" & strFolders(intX)
        End If

        If Len(Dir(strPath, vbDirectory)) = 0 Then
            MkDir strPath
        End If

    Next intX

    MakeFolderPath = 0

Exit_MakeFolderPath:
    Exit Function

Err_MakeFolderPath:
    MakeFolderPath = Err.Number
    MsgBox "Unable to create folder '" & strPath & "'" & vbCr & vbCr & _
            "Error " & Err.Number & ": " & Err.Description, _
            vbExclamation, "Can't Make Folder"
    Resume Exit_MakeFolderPath

End Function
'----- end of code -----
secondly the more complex question is their away i can create a table
that ms access stores the new folder location onces its created the
folder so i can have command button to open that top level folder?

I'm not sure what you have in mind.  Of course you can store the folderpath
in a table -- this is a database, after all -- but the specific details of
what table, what record, what field, and so on, are all up to you.  You
would probably use an inline SQL append or update query to to the actual
insertion.

When you say that you want to "open that top level folder", do you mean that
you want to open the folder in an Explorer window?  If so, you can do it via
the FollowHyperlink method;  for example,

    Application.FollowHyperlink "P:\QUOTATIONS"

or

    Dim strFolderPath As String
    strFolderPath = "P:\QUOTATIONS"
    Application.FollowHyperlink strFolderPath

REPOST LAST MESSAGE DOESNT SEEM TO APPEAR


Damon thanks for you reply i sure give your code a swirl, seems like
less complex.

Dirk Goldgar

thanks for the reply as well, rather interested in the function call
you have made. i only do basic vb such as docmd. etc getting better
though :)

it does refer to ProjectQNo or ProjectTitle, So How Does it know how
to make a Folder in P:\Quotations\ "Q034408 Ambercombie & Fitch"

do i just put that code in the click event of a button? of do i put it
into a modules?

Second Question, I believe i ment is with in the tblProjects Where
Fields ProjectQNo and ProjectTitle are, i will create a field
"FolderLocation" So the theory behind my idea is once a new project
is created the user can click create new folder it will create a
folder in the P:\Quotation\ for that Project, so everything for that
project like word docs, excel, PDF's and so on (So Answer to your
question it is Explorer type folders) and then what id like to happen
is the in the field "folderlocation" it would store the folder
location which will P:\Quotations\"Project Name" for that record, so
if users search for a project and want to see all related documents,
they could click a button and it will open that folder on server for
that project? which out spending age searching through the server and
going through loads of folders.

Regards

Dan
 
D

dan.cawthorne

(re-posting, since my original reply hasn't appeared)
news:b13659c6-d7c3-4b6e-a3ae-e164a3d46ab0@x35g2000hsb.googlegroups.com....
Hi All,
Ive managed to create a command button that  creates a one level entry
folder based on 2 filed on my table  "ProjectQNo" and "ProjectTitle"
and creates the folder where i want it.
this is code i've used
On Error GoTo PROC_ERR
MkDir "P:\QUOTATIONS\" & Me.[ProjectQNo] & " - " & Me.[ProjectTitle]
DoCmd.OpenForm "frm_MakefolderSuccesful"
PROC_EXIT:
Exit Sub
PROC_ERR:
If err.Number = 2101 Then
'take whatever action is appropraite
Else
'perhaps display error message
End If
But I Would Also like to happen is it to create sub folders to, such
as Estimate, Submission and Tender Info
How do i change the code to suit this?
Here's a function that makes an entire folder path, creating any
higher-level folders that don't already exist:
'----- start of code -----
Function MakeFolderPath(PathToMake As String) As Long
    ' Given a complete or relative positional path of which some folders
    ' may not exist, create the complete path including any missingfolders.
    On Error GoTo Err_MakeFolderPath
    Dim strFolders() As String
    Dim strPath As String
    Dim intX As Integer
    If Len(PathToMake) = 0 Then
        Err.Raise 5
    End If
    If Right$(PathToMake, 1) = "\" Then
        strPath = Left$(PathToMake, Len(PathToMake) - 1)
    Else
        strPath = PathToMake
    End If
    strFolders = Split(strPath, "\")
    strPath = vbNullString
    For intX = LBound(strFolders) To UBound(strFolders)
        If intX = LBound(strFolders) Then
            strPath = strFolders(intX)
        Else
            strPath = strPath & "\" & strFolders(intX)
        End If
        If Len(Dir(strPath, vbDirectory)) = 0 Then
            MkDir strPath
        End If
    Next intX
    MakeFolderPath = 0
Exit_MakeFolderPath:
    Exit Function
Err_MakeFolderPath:
    MakeFolderPath = Err.Number
    MsgBox "Unable to create folder '" & strPath & "'" & vbCr & vbCr & _
            "Error " & Err.Number & ": " & Err.Description,_
            vbExclamation, "Can't Make Folder"
    Resume Exit_MakeFolderPath
End Function
'----- end of code -----
I'm not sure what you have in mind.  Of course you can store the folder path
in a table -- this is a database, after all -- but the specific detailsof
what table, what record, what field, and so on, are all up to you.  You
would probably use an inline SQL append or update query to to the actual
insertion.
When you say that you want to "open that top level folder", do you meanthat
you want to open the folder in an Explorer window?  If so, you can doit via
the FollowHyperlink method;  for example,
    Application.FollowHyperlink "P:\QUOTATIONS"

    Dim strFolderPath As String
    strFolderPath = "P:\QUOTATIONS"
    Application.FollowHyperlink strFolderPath
(please reply to the newsgroup)

REPOST LAST MESSAGE DOESNT SEEM TO APPEAR

Damon thanks for you reply i sure give your code a swirl, seems like
less complex.

Dirk Goldgar

thanks for the reply as well, rather interested in the function call
you have made. i only do basic vb such as docmd. etc getting better
though :)

it does refer to ProjectQNo or ProjectTitle, So How Does it know how
to make a Folder in P:\Quotations\ "Q034408 Ambercombie & Fitch"

do i just put that code in the click event of a button? of do i put it
into a modules?

Second  Question, I believe i ment is with in the tblProjects Where
Fields ProjectQNo and ProjectTitle are, i will create a field
"FolderLocation"  So the theory behind my idea is once a new project
is created the user can click create new folder it will create a
folder in the P:\Quotation\ for that Project, so everything for that
project like word docs, excel, PDF's and so on (So Answer to your
question it is Explorer type folders) and then what id like to happen
is the in the field "folderlocation" it would store the folder
location which will P:\Quotations\"Project Name" for that record, so
if users search for a project and want to see all related documents,
they could click a button and it will open that folder on server for
that project? which out spending age searching through the server and
going through loads of folders.

Regards

Dan

since my last reply, I've had play

with opening folders,

i used your code

Dim strFolderPath As String
strFolderPath = Me.FolderLocation
Application.FollowHyperlink strFolderPath

so as long as i have a folder location address in the "folderlocation"
for that record when i click the open button it opens the folder

so just need a way of getting the folder location automaticly added to
that field?

further more ive realized i will need a browse button next to field on
projectlocation on the form just incase some moved folder, so instead
having to type in the new folder location i can just select it?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top