Solved: create folder

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

akabar

Thread Starter
Joined
Sep 16, 2008
Messages
6
hi, currently working on a large MS Word template with many many pages of vba code attached, i'm currently stuck trying to create folders through the vba.

i have tried using the mk dir function to do it, but when i try it says "path not found" or sometimes "path/file access error"

as i am trying to create a folder it seems nonsensical that it is saying the path is not found, of course it's not found, that's why i'm creating it! :mad:

somebody PLEASE help:(
 

Squashman

Retired Trusted Advisor
Joined
Apr 4, 2003
Messages
19,786
Could we see the code where you are making the directory.
mkdir should not have a space in it.
 

akabar

Thread Starter
Joined
Sep 16, 2008
Messages
6
yeah no problem, this is the full code, it uses alot of variables that take information from a selection of userforms and other places, it falls over when it reaches the statement in bold (the first folder in the path which does not currently exist.

Code:
Dim PSRDate As Date
        Dim PSRMonths As String
        Dim PSRYears As String
        Dim FS As New FileSystemObject
                
        PSRDate = Now
        PSRMonths = Mid(Date, 4, 2)
        PSRYears = Right(Date, 2)
        Dim DirPath As String
DirPath = "[URL="file://tvycls01/shareddata/"]\\tvycls01\shareddata\[/URL]" & OfficeName & "\_offender info"
        If FS.folderexists(DirPath) = False Then
           MkDir DirPath
        End If
 
        DirPath = DirPath & "\Probation"
 
        If FS.folderexists(DirPath) = False Then
           MkDir DirPath
        End If
 
        DirPath = DirPath & "\Reports"
 
        If FS.folderexists(DirPath) = False Then
           MkDir DirPath
        End If
 
        DirPath = DirPath & "\PSR Packs"

       If FS.folderexists(DirPath) = False Then
           MkDir DirPath
        End If
 
        DirPath = DirPath & "\" & PSRMonths & "-" & PSRYears
        If FS.folderexists(DirPath) = False Then
           MkDir DirPath
        End If
 
        DirPath = DirPath & "\" & FrmSelect.TxtOffenderFirstName & " " & 
FrmSelect.TxtOffenderSecondName & "-" & FrmSelect.TxtDoB
 
        If FS.folderexists(DirPath) = False Then
           MkDir DirPath
        End If
when this didn't work i tried to make a simpler version in a module of a blank document, just to see if the problem was to do with all the variables, using the exact syntax used in the help file, it was

Code:
MkDir ("[URL="file://tvycls01/shareddata///tvycls01/shareddata/Aylesbury"]\\tvycls01\shareddata\Aylesbury[/URL] - Wynne Jones\_Offender Info\Probation\Reports\psr packs\ ")

the exact same error happened for this as well, i really have no idea why it's doing this. is there any other way of creating a folder through the code other than the mkdir function?
 

Squashman

Retired Trusted Advisor
Joined
Apr 4, 2003
Messages
19,786
Would be helpful to post your resolution, especially since you marked the thread solved.
 

akabar

Thread Starter
Joined
Sep 16, 2008
Messages
6
oh sorry,

partially it was a permissions problem, i was trying to save to the folder for a differant office and didn't have modify rights to the folder in question, but there was still some issue stopping the code from working once i resolved this issue.

the root cause was that where it takes todays date and adds the month and the years to the file path it was taking the slashes between the numbers and that was screwing with the path name.

i used the right and mid functions to take the months and years from the date and seperate them with hyphens rather than with slashes, and that dealt with the problem.

as i said, embaresingly simple solution.
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Members online

Top