mdProgrammer
Programmer
I have a script which has been running fine for 3 years. It runs monthly, and on the 1st of each month, it copies the previous month's data to an archive folder and inserts the month and year into the filename. It works if I do it on my local computer, so I'm guessing it some sort of directory permissions issue, but I tried adding "everyone" as a user and giving all permissions and it still gives the error. I noted where the error occurs in the comments.
Here's my code -
Dim basePath ' The path where the databases are
Dim filePath ' The path where the databases are to be deleted and copied
' Never set the filePath to the root directory!
Dim fileExt ' The file name and extension of the file(s) to be copied
' Do not remove the "\"!
' Set the variables - actual folder names and database names changed for this example.
basePath = "\\dataServer\data"
filePath = "\\dataServer\data\Database Folder"
fileExt = "\SomeDatabaseString*.mdb"
' Copy current database into database folder with month/year date stamp inserted into the filename.
dim filesys
set filesys=CreateObject("Scripting.FileSystemObject")
filesys.CopyFile basePath & fileExt, filePath ' Copy files to new directory
Dim fso,f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(basePath)
For Each file In f.Files
if UCase(Right(file.Name, 3)) = "MDB" Then
'msgbox filePath & "\" & file.Name
'msgbox filePath & "\" & Left(file.Name,(len(file.Name)-4)) & " " & MonthName(Month(Date())) & " " & Year(Date()) & ".mdb"
' ###### The error occurs here -
fso.MoveFile filePath & "\" & file.Name, filePath &_
"\" & Left(file.Name,(len(file.Name)-4)) &_
" " & MonthName(Month(Date())) & " " & Year(Date()) & ".mdb"
end if
Next
Set fso = Nothing
Here's my code -
Dim basePath ' The path where the databases are
Dim filePath ' The path where the databases are to be deleted and copied
' Never set the filePath to the root directory!
Dim fileExt ' The file name and extension of the file(s) to be copied
' Do not remove the "\"!
' Set the variables - actual folder names and database names changed for this example.
basePath = "\\dataServer\data"
filePath = "\\dataServer\data\Database Folder"
fileExt = "\SomeDatabaseString*.mdb"
' Copy current database into database folder with month/year date stamp inserted into the filename.
dim filesys
set filesys=CreateObject("Scripting.FileSystemObject")
filesys.CopyFile basePath & fileExt, filePath ' Copy files to new directory
Dim fso,f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(basePath)
For Each file In f.Files
if UCase(Right(file.Name, 3)) = "MDB" Then
'msgbox filePath & "\" & file.Name
'msgbox filePath & "\" & Left(file.Name,(len(file.Name)-4)) & " " & MonthName(Month(Date())) & " " & Year(Date()) & ".mdb"
' ###### The error occurs here -
fso.MoveFile filePath & "\" & file.Name, filePath &_
"\" & Left(file.Name,(len(file.Name)-4)) &_
" " & MonthName(Month(Date())) & " " & Year(Date()) & ".mdb"
end if
Next
Set fso = Nothing