Run-Time Error 5 ... Invalid Procedure Call

lucour

Registered User.
Local time
Today, 22:50
Joined
Mar 7, 2001
Messages
60
Hello,

I have the following module setup in Access 2003, that is supposed to rename a .pdf file and then move it to another folder. When I attempt to run this, it aborts with the message 'Run-Time error 5 ..Invalid Procedure Call or Argument'. The Debugger traces back to this line:
objFS.MoveFile strSourcePath & objF1.NAME, strDestPath

Can anyone provide any insight ? Thank you.

Function AssetCopy()

Dim objFS As Object, objFolder As Object
Dim objFiles As Object, objF1 As Object
Dim strFill As String, strSourcePath As String, strDestPath As String
Dim OldFName As String, NewFName As String, NDate As Date, NewFileName As String, OldPath As String

strSourcePath = "D:\CGI CTI\Asset Management\CGI Inventory\Monthly Reports\PDFHold\" 'This is the drive the files are residing
strSDestPath = "D:\CGI CTI\Asset Management\CGI Inventory\Monthly Reports\TempHold\" 'This is the drive the files are residing


Set objFS = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFS.GetFolder(strSourcePath)
Set objFiles = objFolder.Files


'OldPath = "C:\Access2000\Scripts\PDFHold\"
OldFName = "D:\CGI CTI\Asset Management\CGI Inventory\Monthly Reports\PDFHold\PDFReport.pdf"
NewFName = "D:\CGI CTI\Asset Management\CGI Inventory\Monthly Reports\PDFHold\AssetReport.pdf"

'NewFileName = OldFName & NDate
Name OldFName As NewFName

For Each objF1 In objFiles
'This is the drive to copy to.
objFS.MoveFile strSourcePath & objF1.NAME, strDestPath

Next



Set objF1 = Nothing
Set objFiles = Nothing
Set objFolder = Nothing
Set objFS = Nothing

End Function
 
Your problem is that you are using strDestPath which is just the path and not including the file name. You need to include the file name on there too.
 
Run-Time Error 5

I get a 'Run-Time Error 5 Invalid Procedure Call or Argument' error when running the following module:

Function AssetCopy()

Dim objFS As Object, objFolder As Object
Dim objFiles As Object, objF1 As Object
Dim strFill As String, strSourcePath As String, strDestPath As String
Dim OldFName As String, NewFName As String, NDate As Date, NewFileName As String, OldPath As String

strSourcePath = "D:\CGI CTI\Asset Management\CGI Inventory\Monthly Reports\PDFHold\" 'This is the drive the files are residing
strSDestPath = "D:\CGI CTI\Asset Management\CGI Inventory\Monthly Reports\TempHold\" 'This is the drive the files are residing


Set objFS = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFS.GetFolder(strSourcePath)
Set objFiles = objFolder.Files


'OldPath = "C:\Access2000\Scripts\PDFHold\"
OldFName = "D:\CGI CTI\Asset Management\CGI Inventory\Monthly Reports\PDFHold\PDFReport.pdf"
NewFName = "D:\CGI CTI\Asset Management\CGI Inventory\Monthly Reports\PDFHold\AssetReport.pdf"

'NewFileName = OldFName & NDate
Name OldFName As NewFName

For Each objF1 In objFiles
'This is the drive to copy to.
objFS.MoveFile strSourcePath & objF1.NAME, strDestPath

'End If
Next



Set objF1 = Nothing
Set objFiles = Nothing
Set objFolder = Nothing
Set objFS = Nothing

End Function

It abends on the 'objFS.MoveFile strSourcePath & objF1.NAME, strDestPath' step.

Can anyone help ?
 
As the code stands now.....the String Variable strDestPath contains nothing (empty String) so what you are trying to do is move whatever is contained within strSourcePath & objF1.NAME to nothing. Not good.

Here's why:

You've declared the variable strDestPath but further down the code you have not filled this specific variable with anything. You did however fill the variable strSDestPath. Whoops...a typo. Remove the S from strSDestPath.

To eliminate problems like this, ALL your code modules should contain Option Explicit statement so as to force explicit declaration of all variables in that module. That way, when the code is compiled the problem is detected and pinpointed right away.

objFS.MoveFile strSourcePath & objF1.NAME, strDestPath & objF1.NAME

.
 
Last edited:
Thanks CybeLynx .... You are correct. I had the variable misnamed. When I changed it to strDestPath, it ran fine. As well, I added the 'Option Explicit' declaration to the code. Thank you for your help, as well as the others who replied......... Lucour.
 

Users who are viewing this thread

Back
Top Bottom