Public Function BackupDatabases()
'You must set a reference to the Microsoft Scripting Runtime
Dim fso As FileSystemObject
Dim sSourceFile As String
Dim sBackupPath As String
Dim sBackupFile As String
Dim sFileName As String
Dim lngRecord As Long
With CurrentDb.OpenRecordset("tblBackUpFiles", dbOpenDynaset)
.MoveLast
.MoveFirst
SysCmd acSysCmdInitMeter, "Backing Up Files...", .RecordCount
For lngRecord = 1 To .RecordCount
sSourceFile = !FilePathName
sFileName = ParseFileName(sSourceFile)
sBackupPath = !BackUpPath
sBackupFile = sFileName & "_" & Format(Date, "yyyy-mm-dd") & "_" & Format(Time, "hhnnss") & ".mdb"
Set fso = New FileSystemObject
fso.CopyFile sSourceFile, sBackupPath & sBackupFile, True
Set fso = Nothing
SysCmd acSysCmdUpdateMeter, lngRecord
.MoveNext
Next lngRecord
SysCmd acSysCmdRemoveMeter
End With
MsgBox "Backups finished"
End Function
Public Function ParseFileName(sFile As String) As String
On Error GoTo Err_ParseFileName
Dim sPath As String
sPath = sFile
Do While Right$(sPath, 1) <> "\"
sPath = Left$(sPath, Len(sPath) - 1)
Loop
ParseFileName = Mid$(sFile, Len(sPath) + 1)
Exit_ParseFileName:
Exit Function
Err_ParseFileName:
MsgBox Err.Number & " - " & Err.Description
Resume Exit_ParseFileName
End Function