Private Sub Command0_Click()
BackupAndZipit
End Sub
Private Sub Command1_Click()
MoveFiles
End Sub
Public Function BackupAndZipit()
'This function will allow you to copy a db that is open,
'rename the copied db and zip it up to anther folder.
'You must set a reference to the 'Microsoft Scripting Runtime' for the CopyFile piece to work!
'Thanks to Ricky Hicks for the .CopyFile code
DoCmd.SetWarnings True
Dim fso As FileSystemObject
Dim sSourcePath As String
Dim sSourceFile As String
Dim sBackupPath As String
Dim sBackupFile As String
sSourcePath = "Z:\ORG\data\"
sSourceFile = "data.mdb"
sBackupPath = "F:\"
sBackupFile = "BackupDB_.mdb"
Set fso = New FileSystemObject
fso.CopyFile sSourcePath & sSourceFile, sBackupPath & sBackupFile, True
Set fso = Nothing
Dim sWinZip As String
Dim sZipFile As String
Dim sZipFileName As String
Dim sFileToZip As String
sWinZip = "C:\Program Files\WinRAR\winrar.exe" 'Location of the WinZip program
sZipFileName = Left(sBackupFile, InStr(1, sBackupFile, ".", vbTextCompare) - 1) & ".rar"
'sZipFileName = "BackupDB_.RAR"
sZipFile = sBackupPath & sZipFileName
sFileToZip = sBackupPath & sBackupFile
'winrar a -afzip F:\BackupDB_.rar F:\BackupDB_.mdb
Call Shell(sWinZip & " a -afzip " & sZipFile & " " & sFileToZip, vbHide)
End Function
Public Function MoveFiles()
Dim Msg, Style, Title, Help, Ctxt, Response, MyString
Msg = "Do you like to delete temp file ?" ' Define message.
Style = vbYesNo + vbCritical + vbDefaultButton2 ' Define buttons.
Title = "Delete your Temp File" ' Define title.
Help = "DEMO.HLP" ' Define Help file.
Ctxt = 1000 ' Define topic
' context.
' Display message.
Dim sSourcePath2 As String
Dim sSourceFile2 As String
Dim sBackupPath2 As String
Dim sBackupFile2 As String
Dim sSourcePath As String
Dim sSourceFile As String
Dim sBackupPath As String
Dim sBackupFile As String
Dim I As Double
sSourcePath = "Z:\ORG\data\"
sSourceFile = "data.mdb"
sBackupPath = "F:\"
sBackupFile = "BackupDB_.mdb"
sSourcePath2 = "F:\"
sSourceFile2 = "BackupDB_.rar"
sBackupPath2 = "E:\"
sBackupFile2 = "BackupDB_" & Format(Date, "mmddyyyy") & "_" & Format(Time, "hhmmss") & ".rar"
Set fso = New FileSystemObject
fso.CopyFile sSourcePath2 & sSourceFile2, sBackupPath2 & sBackupFile2, True
Set fso = Nothing
I = 1
Beep
Response = MsgBox(Msg, Style, Title, Help, Ctxt)
If Response = vbYes Then
If Dir(sBackupPath & sBackupFile) <> "" Then Kill (sBackupPath & sBackupFile)
If Dir(sSourcePath2 & sSourceFile2) <> "" Then Kill (sSourcePath2 & sSourceFile2)
End If
End Function