Public Sub RenameMoveFiles()
Const ARCHIVE_FOLDER As String = "N:\AGT\IT\Opdrachten\2012\Schatkistbankieren Aanvraagform\ExcelBestanden\Archive\"
Dim FSO As New FileSystemObject
Dim oFile As File
Dim dbs As DAO.Database
Dim rs As DAO.Recordset
Dim sSQL As String
Dim sAntFix As String
Dim sNewName As String
Dim sFileExt As String
sSQL = "Select ExcelFileID,ExcelFileName, ExcelFilePath, WorkbookLastModified " _
& "From tExcelFiles " _
& "Where Processed = -1"
Set dbs = CurrentDb
Set rs = dbs.OpenRecordset(sSQL)
With rs
If .BOF And .EOF Then 'no files to move
MsgBox "No files to move", vbExclamation
.Close
Exit Sub
End If
.MoveFirst
Do Until .EOF
sAntFix = "_" & Format(.Fields("WorkbookLastModified").Value, "yyyymmdd")
Set oFile = FSO.GetFile(.Fields("ExcelFilePath").Value)
sFileExt = "." & FSO.GetExtensionName(.Fields("ExcelFilePath").Value)
sNewName = ARCHIVE_FOLDER & Replace(oFile.Name, sFileExt, sAntFix & sFileExt)
oFile.Move (sNewName)
.MoveNext
Loop
.Close
End With
Set rs = Nothing
Set dbs = Nothing
End Sub