Hi guys,
i am using the following vba code to backup my database.
Code:
Dim Source As String
Dim Target As String
Dim retval As Integer
Dim BckFileDateTime As Variant
'The Source database to backup. Set to the current database
Source = CurrentDb.name
'Set current date and time
BckFileDateTime = Format(Date, "dd-mm-yyyy ") & Format(time, "hh-mm-ss")
'The path where we save the backup file. Set to current source path + a folder called dbBackup
Target = CurrentProject.Path & "\dbBackup\DbBackup_@_"
'Add the current date and time to the filename
Target = Target & BckFileDateTime & ".accdb"
' create the backup
retval = 0
Dim objFSO As Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
retval = objFSO.CopyFile(Source, Target, True)
Set objFSO = Nothing
'Opens the folder of the file you just created
Application.FollowHyperlink CurrentProject.Path
The above works as expected. Now i would like to compress/zip the backup file, and then delete the initial non compressed/zipped file.
i have tried the following but not working.
Code:
Dim sWinZip As String
Dim sZipFile As String
Dim sZipFileName As String
Dim sFileToZip As String
sWinZip = "C:\Program Files\WinZip\winzip64.exe" 'Location of the WinZip program
sZipFileName = "sample" & ".zip"
sZipFile = CurrentProject.Path & "\dbBackup\" & sZipFileName
'sFileToZip = sBackupPath & sBackupFile
Call Shell(sWinZip & " -a " & sZipFile & " " & sFileToZip, vbHide)
Beep
MsgBox "Backup was successful and saved @ " & Chr(13) & sZipFileName, vbInformation, "Backup Completed"
Wanted to use windows explorer to perform the compression/zipping but don't know how to go about it, that's why i sticked to * sWinZip = "C:\Program Files\WinZip\winzip64.exe" 'Location of the WinZip program *
Can someone possibly help me massage the initial backup code to include the compress/zip functionality using the windows explorer?
Thank you.