Backups

GavZ

Mostly Beginners Luck!
Local time
Today, 06:28
Joined
May 4, 2007
Messages
56
I got this code from one of ghudson's posts and am having a bit of trouble with it. Heres the code:


Public Function BackupAndZipit()

Dim fso As FileSystemObject

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

sSourcePath = "Q:\CID\Covert Operations\Accessing Communications Data\++SPOC INFORMATION DATABASE++\"
sSourceFile = "Invoice DB.mdb"
sBackupPath = "Q:\CID\Covert Operations\Accessing Communications Data\++SPOC INFORMATION DATABASE++\Backups\"
sBackupFile = "BackupDB_" & Format(Date, "mmddyyyy") & "_" & 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 = "N:\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



i can get it to run ok on one db (of path h:\personal\invoicedb.mdb) but when i try to do it on another (above) it doesnt work. I think it is because there is spaces in the folder names because it comes up with the error:

'Error: No files were found for this action that match your criteria - nothing to do. (Q:\CID\Covert.zip)

How can i get around this?

Thanks in advance
 
Try this change

Code:
sSourcePath = chr(34) & "Q:\CID\Covert Operations\Accessing Communications Data\++SPOC INFORMATION DATABASE++\"
sSourceFile = "Invoice DB.mdb" & chr(34)
sBackupPath = chr(34) & "Q:\CID\Covert Operations\Accessing Communications Data\++SPOC INFORMATION DATABASE++\Backups\"
sBackupFile = "BackupDB_" & Format(Date, "mmddyyyy") & "_" & Format(Time, "hhmmss") & ".mdb" & chr(34)

This will put the strings in quotes ehich will work even if there are spaces in the directory/file names.

HTH
 
Favour: Can someone open this and save it as A97 please! :D
 

Users who are viewing this thread

Back
Top Bottom