N
niuginikiwi
I have come up with this function that check to see if record locking file
ldb exists for the backend database and if it doesn't , it copies the be db
to a new into another directory. Refer to code below...
But I want to do more than this, actually I would like to compact and repair
the database first and then do a backup copy. Can anyone add onto the
function below and show me how its done or even some tips and suggestions
would help.
Option Compare Database
Function DoBackup()
On Error GoTo Err_DoBackup
Dim strBackupFile As String
Dim strCurrentFile As String
Dim strDateStamp As String
Dim strCurrentLockFile As String
strCurrentFile = Application.CurrentProject.Path & "\DataFile.mdb"
DoCmd.Hourglass True
strDateStamp = Format(Date, "yyyy_mm_dd")
strBackupFile = Application.CurrentProject.Path & "\Backup\" &
strDateStamp & ".mdb"
strCurrentLockFile = Application.CurrentProject.Path & "\DataFile.ldb"
If Len(Dir(strCurrentLockFile)) > 0 Then
MsgBox "Cannot backup the database: it's in use", , "Backup "
Else
If Len(Dir(strBackupFile)) > 0 Then
Kill strBackupFile
End If
FileCopy strCurrentFile, strBackupFile
DoCmd.Beep
MsgBox "Database backup successful...", , "Backup Confirmation"
End If
' Copy the database
DoCmd.Hourglass False
Exit_DoBackup:
Exit Function
Err_DoBackup:
MsgBox Str(Err)
MsgBox Error$
Resume Exit_DoBackup
End Function
ldb exists for the backend database and if it doesn't , it copies the be db
to a new into another directory. Refer to code below...
But I want to do more than this, actually I would like to compact and repair
the database first and then do a backup copy. Can anyone add onto the
function below and show me how its done or even some tips and suggestions
would help.
Option Compare Database
Function DoBackup()
On Error GoTo Err_DoBackup
Dim strBackupFile As String
Dim strCurrentFile As String
Dim strDateStamp As String
Dim strCurrentLockFile As String
strCurrentFile = Application.CurrentProject.Path & "\DataFile.mdb"
DoCmd.Hourglass True
strDateStamp = Format(Date, "yyyy_mm_dd")
strBackupFile = Application.CurrentProject.Path & "\Backup\" &
strDateStamp & ".mdb"
strCurrentLockFile = Application.CurrentProject.Path & "\DataFile.ldb"
If Len(Dir(strCurrentLockFile)) > 0 Then
MsgBox "Cannot backup the database: it's in use", , "Backup "
Else
If Len(Dir(strBackupFile)) > 0 Then
Kill strBackupFile
End If
FileCopy strCurrentFile, strBackupFile
DoCmd.Beep
MsgBox "Database backup successful...", , "Backup Confirmation"
End If
' Copy the database
DoCmd.Hourglass False
Exit_DoBackup:
Exit Function
Err_DoBackup:
MsgBox Str(Err)
MsgBox Error$
Resume Exit_DoBackup
End Function