G
Gntlhnds
I am trying to incorporate some code to compact/backup my backend, but since
my backend resides on a server and the front end is on my local machine, it
doesn't work. What I would like to do is utilize the GetOpenFileName dialog
to browse to the backend. Here's the code that I have now:
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 & "\Tables.mdb"
DoCmd.Hourglass True
strDateStamp = Format(Date, "yyyy_mm_dd")
strBackupFile = Application.CurrentProject.Path & "\Backup\" &
strDateStamp & ".mdb"
strCurrentLockFile = Application.CurrentProject.Path & "\Tables.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
Application.CompactRepair strCurrentFile, strBackupFile
Kill strCurrentFile ' or better to rename it
Application.CompactRepair strBackupFile, strCurrentFile
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
This code works great if the FE and BE are in the same folder. Since I
don't know the path to the backend for my users, I prefer to use the
GetOpenFileName dialog to browse to it and also to specify the name and
location of the backup file (preferably with a default name filled in for
them to change if they like). Thanks for your help.
my backend resides on a server and the front end is on my local machine, it
doesn't work. What I would like to do is utilize the GetOpenFileName dialog
to browse to the backend. Here's the code that I have now:
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 & "\Tables.mdb"
DoCmd.Hourglass True
strDateStamp = Format(Date, "yyyy_mm_dd")
strBackupFile = Application.CurrentProject.Path & "\Backup\" &
strDateStamp & ".mdb"
strCurrentLockFile = Application.CurrentProject.Path & "\Tables.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
Application.CompactRepair strCurrentFile, strBackupFile
Kill strCurrentFile ' or better to rename it
Application.CompactRepair strBackupFile, strCurrentFile
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
This code works great if the FE and BE are in the same folder. Since I
don't know the path to the backend for my users, I prefer to use the
GetOpenFileName dialog to browse to it and also to specify the name and
location of the backup file (preferably with a default name filled in for
them to change if they like). Thanks for your help.