Tech Support Guy banner
  • Please post in our Community Feedback thread for help with the new forum software! If you are having trouble logging in, please Contact Us for assistance.
Status
Not open for further replies.
1 - 6 of 6 Posts

·
Registered
Joined
·
6 Posts
Discussion Starter · #1 ·
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:(
 

·
Registered
Joined
·
6 Posts
Discussion Starter · #3 ·
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?
 

·
Registered
Joined
·
6 Posts
Discussion Starter · #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.
 
1 - 6 of 6 Posts
Status
Not open for further replies.
Top