0
votes

I want to move folders which are on network using Access VBA.

When I click button on form, it shall execute VBA code.

The below program moves local PC folders, when \\?\ is removed from the code. Using \\?\ before any network folder path, it is creating new folder on network.

When I want to move folders it is giving:

Run time Error 5 : Invalid Procedure call or Argument.

Upon debug , it highlights objF.MoveFolder oldStr, newStr

Private Sub btnBrowse_Click()
Dim oldStr As String
Dim newStr As String
Dim objF As Object

Me.OldPath = Me.FolderPath
Me.NewPath = GetFolder()

If Len(Me.NewPath) > 0 Then
     Me.NewPath = "\\?\" & Me.NewPath
     Me.FolderPath = Me.NewPath

     Set objF = CreateObject("Scripting.FileSystemObject")

     oldStr = Me.OldPath & "\*"
     newStr = Me.NewPath & "\"

     objF.MoveFolder oldStr, newStr
End If

End Sub
2
From Help You passed an invalid parameter in your procedure call. This could be because the parameter was out of range, or contained invalid data. Alternately, you may have invoked a procedure at an unexpected time. To correct this error Verify that the parameters being passed to the procedure are valid. Verify that you are calling the function at an appropriate time.. So msgbox out the paths. - Noodles
For the local path i.e. C:\blahblah blah it works well. i.e. moving Folders. For modified path i.e. \?\\G:\blahblahblah ( actual network path is G:\blahblahblah ) ; the access is capable of creating New Folder in the network path. However only Folder Movement is not happening with \?\\G:blahblahblah - Mahesh Bolavakar
You can't use these paths. Use conventional paths. \\?\ has noting to do with networks. Networks are \\servername\sharename\folder\file.ext - Noodles
Actually before your comments only, I removed \\?\ and it was working all good. \\?\ was creating confusion to MS Access in recognizing path, & thus was throwing error. Thanks for your help @Noodles - Mahesh Bolavakar
It's nothing to do with Access. Its to do with "Scripting.FileSystemObject". Pathnames are limited to 260 characters, so programs only allocate a maximum of that to store paths (520 bytes). NTFS allows paths of 32K characters. \\?\ tells windows the programs knows the path can be up to 32K and Windows turns off checks for legal windows filenames. - Noodles

2 Answers

0
votes

Use Microsoft.Scripting.Runtime file object to move folder.

0
votes

We can't use these \\?\ paths. Should use conventional paths. \\?\ has noting to do with networks. Networks are \\servername\sharename\folder\file.ext

I removed \\?\ and it was working all good. \\?\ was creating confusion to MS Access in recognizing path, & thus was throwing error.