Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mkdir Error 76 with Environment Variable

Status
Not open for further replies.

03Explorer

Technical User
Sep 13, 2005
304
US
I get the error on line 8. I have tried numerous ways. The system is windows 10 (if that matters) using Access 365.

Code:
        CompiledDirectory = "%LocalAppData%\Synergy\Compiled\"  
        Dim fdObj As Object
        Set fdObj = CreateObject("Scripting.FileSystemObject")
        If fdObj.FolderExists(CompiledDirectory) Then
            Debug.Print "Found it"  '-- Should trigger every time after initial run of Synergy PER user
        Else
              Debug.Print CompiledDirectory
                MkDir CompiledDirectory

              Debug.Print "It has been created."  '-- Should trigger once per user, upon first initial run of Synergy
        End If
 
%<specialfoldername>% environmemnt variables are understood and expanded by the SHell (so Explorer, for example, or the commandline) but not by the filesystemobject or by most VBA commands (i.e. mkdir). So leverage the shell … e.g
.
Code:
[blue]Public Sub example()
    CompiledDirectory = Expand("%LocalAppData%") & "\Synergy\Compiled\"
    Dim fdObj As Object
    Set fdObj = CreateObject("Scripting.FileSystemObject")
    If fdObj.FolderExists(CompiledDirectory) Then
        Debug.Print "Found it"  [green]'-- Should trigger every time after initial run of Synergy PER user[/green]
    Else
        Debug.Print CompiledDirectory
        MkDir CompiledDirectory
    
        Debug.Print "It has been created."  [green]'-- Should trigger once per user, upon first initial run of Synergy[/green]
    End If
End Sub

Public Function Expand(strName As String)
    With CreateObject("wscript.shell")
        Expand = .ExpandEnvironmentStrings(strName)
    End With
End Function[/blue]

 
@strongm I adjusted the code to incorporate your suggestion above; leveraging the shell. I am getting the same error '76' Path not found.

Code:
'
        CompiledDirectory = "%LocalAppData%\Synergy\Compiled\"  '- Source for Compiled/Output files  WITH last character as SLASH '\'
        Dim fdObj As Object
        Set fdObj = CreateObject("Scripting.FileSystemObject")
        If fdObj.FolderExists(CompiledDirectory) Then
            Debug.Print "Found it"  '-- Should trigger every time after initial run of Synergy PER user
        Else
            Debug.Print CompiledDirectory
            MkDir CompiledDirectory
            Debug.Print "It has been created."  '-- Should trigger once per user, upon first initial run of Synergy
        End If

The debug print for Compiled directory comes out with code I can copy from Immediate window and manually go to command prompt and paste in a mkdir command... It works! Why not in the code?? Is there an environment issue that I am not considering? like local rights?
 
strongm:
Code:
[blue]CompiledDirectory = Expand("%LocalAppData%") & "\Synergy\Compiled\"[/blue]
03Explorer
Code:
CompiledDirectory = "%LocalAppData%\Synergy\Compiled\"

There is a difference...


---- Andy

There is a great need for a sarcasm font.
 
Got it... in the copy/paste I seem to have grabbed coding that didn't have your routine called (Expand) however I manually created the folders and it never triggers the "Found it" portion of the code... =
I feel like a heel pasting my old code vs the one which I used your routine. Thanks! =)
 
>manually go to command prompt and paste in a mkdir command.

Indeed. But as I said, the commandline commands know how to expand environment variables. VBA commands, even if they have the same name (eg mkdir) do not.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top