S
Stapes
Hi
I am trying to make a routine to back up the data which resides in a
back end database.
I am copying my back end file to a new file, then compacting the new
file into another file.
I then want to copy the newly compacted file back to the original back
end.
To do this, I want to close the current database ( but keep executing
my vb commands), do the copy, then re-open the database. Can I do
this?
This is my code:
Private Sub Command43_Click()
On Error GoTo Err_Command43_Click
Dim fileObj As Object
Dim strBackEndName As String
Dim strBackupName As String
Dim strCompacted As String
Dim msg As Integer
Dim strPath As String
Dim db As Database
Set db = CurrentDb
Let strBackEndName = "SCOPS_BEdb1.mdb"
strCompacted = Format$(Now(), "yyyymmddhms") & "_BUCR_" &
strBackEndName
Let strBackupName = Format$(Now(), "yyyymmddhms") & "_BU_" &
strBackEndName
strPath = CurrentDb().Name
strPath = Left$(strPath, _
Len(strPath) - Len(Dir(strPath)))
Let strBackEndName = strPath & strBackEndName
Let strBackupName = strPath & "Reserve\" & strBackupName
Set fileObj = CreateObject("scripting.filesystemobject")
fileObj.CopyFile strBackEndName, strBackupName, True
msg = MsgBox("A backup of the existing database has been stored as:" _
& vbCrLf & vbCrLf & _
strBackupName, vbInformation)
strCompacted = strPath & "Reserve\" & strCompacted
DBEngine.CompactDatabase strBackupName, strCompacted
msg = MsgBox(strBackupName & "has been compacted and repaired as:" _
& vbCrLf & vbCrLf & _
strCompacted, vbInformation)
fileObj.CopyFile strCompacted, strBackEndName, True
msg = MsgBox(strCompacted & "has been copied back to:" _
& vbCrLf & vbCrLf & _
strBackEndName, vbInformation)
Exit_Command43_Click:
Exit Sub
Err_Command43_Click:
MsgBox Err.Number & ":" & Err.Description
End Sub
Stapes
I am trying to make a routine to back up the data which resides in a
back end database.
I am copying my back end file to a new file, then compacting the new
file into another file.
I then want to copy the newly compacted file back to the original back
end.
To do this, I want to close the current database ( but keep executing
my vb commands), do the copy, then re-open the database. Can I do
this?
This is my code:
Private Sub Command43_Click()
On Error GoTo Err_Command43_Click
Dim fileObj As Object
Dim strBackEndName As String
Dim strBackupName As String
Dim strCompacted As String
Dim msg As Integer
Dim strPath As String
Dim db As Database
Set db = CurrentDb
Let strBackEndName = "SCOPS_BEdb1.mdb"
strCompacted = Format$(Now(), "yyyymmddhms") & "_BUCR_" &
strBackEndName
Let strBackupName = Format$(Now(), "yyyymmddhms") & "_BU_" &
strBackEndName
strPath = CurrentDb().Name
strPath = Left$(strPath, _
Len(strPath) - Len(Dir(strPath)))
Let strBackEndName = strPath & strBackEndName
Let strBackupName = strPath & "Reserve\" & strBackupName
Set fileObj = CreateObject("scripting.filesystemobject")
fileObj.CopyFile strBackEndName, strBackupName, True
msg = MsgBox("A backup of the existing database has been stored as:" _
& vbCrLf & vbCrLf & _
strBackupName, vbInformation)
strCompacted = strPath & "Reserve\" & strCompacted
DBEngine.CompactDatabase strBackupName, strCompacted
msg = MsgBox(strBackupName & "has been compacted and repaired as:" _
& vbCrLf & vbCrLf & _
strCompacted, vbInformation)
fileObj.CopyFile strCompacted, strBackEndName, True
msg = MsgBox(strCompacted & "has been copied back to:" _
& vbCrLf & vbCrLf & _
strBackEndName, vbInformation)
Exit_Command43_Click:
Exit Sub
Err_Command43_Click:
MsgBox Err.Number & ":" & Err.Description
End Sub
Stapes