strDBNameBackup = Left(strDBName, Len(strDBName) - 4) _
& “ Backup for “ & FormatDateTime(Date(), 1) _
& “.mdb”
MsgBox “Backup name: “ & strDBNameBackup
strBackupNameAndPath = strDBPath & strDBNameBackup
Check that the database is in the specified folder, and quit if it is not found:
On Error Resume Next
Set fso = _
WScript.CreateObject(“Scripting.FileSystemObject”)
Set fil = fso.GetFile(strDBNameAndPath)
‘MsgBox “Error #: “ & Err
If fil Is Nothing Then
strPrompt = “Can’t find “ & strDBName & _
“ in “ & strDBPath & “ folder; canceling”
MsgBox strPrompt, vbCritical + vbOKOnly
Quit
Else
Copy the database to a backup:
fso.CopyFile strDBNameAndPath, strBackupNameAndPath, _
True
MsgBox strDBName & “ copied to “ _
& strDBPath & “ as “ & strDBNameBackup
End If
You can run this script manually, but for assurance that a backup will be made every day, you can
schedule the script to run from the Windows Task Scheduler. To open the Task Scheduler, first
open the Control Panel, and select the Administrative Tools program group (Figure 17.18).
In the Administrative Tools program group, select the Task Scheduler, as shown in Figure 17.19. If
you get a UAC message, click Continue.
Part III Adding More Functionality to Office