Backup without Zipping

Alan R

Registered User.
Local time
Today, 00:46
Joined
Sep 11, 2006
Messages
70
Hi,

I have been using the following code (thanks ghudson) to backup and zip a database.

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

Dim fso As FileSystemObject

Dim sSourcePath As String
Dim sSourceFile As String
Dim sBackupPath As String
Dim sBackupFile As String

sSourcePath = "C:\Daves Database\"
sSourceFile = "Daves Database.mdb"
sBackupPath = "C:\Backup\"
sBackupFile = "BackupDB_" & Format(Date, "ddmmmyyyy") & "_" & Format(Time, "hhmmss") & ".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\WinZip\WinZip32.exe" 'Location of the WinZip program
sZipFileName = Left(sBackupFile, InStr(1, sBackupFile, ".", vbTextCompare) - 1) & ".zip"
sZipFile = sBackupPath & sZipFileName
sFileToZip = sBackupPath & sBackupFile

Call Shell(sWinZip & " -a " & sZipFile & " " & sFileToZip, vbHide)

Beep
MsgBox "Backup was successful and saved @ " & Chr(13) & Chr(13) & sBackupPath & Chr(13) & Chr(13) & "The backup file name is " & Chr(13) & Chr(13) & sZipFileName, vbInformation, "Backup Completed"

If Dir(sBackupPath & sBackupFile) <> "" Then Kill (sBackupPath & sBackupFile)

End Function


However i would prefer it if it didn't zip it and just created a backup, i have tried 'removing' those elements i believe are involved only with the Zipping process and the function gets to the end and creates the Message Box but no back up is created.

Can anybody help me please?

Many Thanks

Alan
 
If Dir(sBackupPath & sBackupFile) <> "" Then Kill (sBackupPath & sBackupFile)

its the kill statement thats doing it
this line is deleted the unzipped backup, so comment this line out also
 
Gemma,

Many thanks for your reply.

That works, strange thing is is that i am certain i tried that :confused: but anyway it is working now:)

Alan
 
Hi Allan!

Your post is exactly what i needed! Forgive a novice but.. can you please elaborate more on how to go about the code? I mean, how do i use it?

Thanks!

Sheila
 
Back up coding

Shelia,

i don't have access to the db i used this in and is from memory, so apologies if it is a bit vague.

I created a module and called it something like Backup, within this module i added a Public Function called BackUpAndZipIt into which i copied the code you see in the first posting.

Then using code behind a button On Click event i called the Public Function BackupAndZipIt.

Since i didn't want the zip capability, i commented out all the lines of code associated with that so it only made a backup of the db as if you selected backup from File menu. The reason i chose to do it this way is because i combined a number of housekeeping tasks together such as backup, empty certain tables, reset numbering, reset dates etc all on one button.

I hope that helps, if not let me know and i will try to make things clearer. On Saturday i should be able to get to the db i included this in so will be able to give a better answer is still required - let me know how you get on.

You will also need to ensure that the following:

sSourcePath = "C:\Daves Database\"
sSourceFile = "Daves Database.mdb"
sBackupPath = "C:\Backup\"

are correctly set up for your system.

Regards

Alan
 

Users who are viewing this thread

Back
Top Bottom