By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,991 Members | 1,737 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,991 IT Pros & Developers. It's quick & easy.

zip backup file to A:\ problem

P: n/a
I have this code to find a file, place it in C:\ temp, zip it up then send it
to floppy in drive A:\.

When I run it it comes up with error 53 - source file not found. However it
gets as far as putting the file and the zipped file into C:\ temp.

Any thoughts on what is causing this ?
David B
Hexham UK


Public Function BackupAndZipitToDriveA()
On Error GoTo Err_BackupAndZipitToDriveA

'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:\Data\adata\Stock record\Hoofprint\"
sSourceFile = "Stock _be.mdb"

If Dir("C:\Temp", vbDirectory) = "" Then MkDir ("C:\Temp")
sBackupPath = "C:\Temp\"
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 = "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)
Name sZipFile As "A:\" & sZipFileName
Beep
MsgBox "Backup was successful and saved @ " & Chr(13) & Chr(13) & "A:\" &
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)

Exit_BackupAndZipitToDriveA:
Exit Function

Err_BackupAndZipitToDriveA:
If Err = 5 Then 'Invalid procedure call or argument
Beep
MsgBox "Disk is full! Can not move the zip file to the A:\ drive.
Please move the " & sZipFile & " file to a safe location." & vbNewLine &
vbNewLine & sSourceFile, vbCritical
If Dir(sBackupPath & sBackupFile) <> "" Then Kill (sBackupPath &
sBackupFile)
Exit Function
ElseIf Err = 53 Then 'File not found
Beep
MsgBox "Source file can not be found!" & vbNewLine & vbNewLine &
sSourceFile, vbCritical
Exit Function
ElseIf Err = -2147024784 Then 'Method 'CopyFile' of object 'IFileSystem3'
faild
Beep
MsgBox "File is to large to be zipped onto the A:\ drive!" & vbNewLine &
vbNewLine & sSourceFile, vbCritical
Exit Function
Else
MsgBox Err.Number & " - " & Err.Description
Resume Exit_BackupAndZipitToDriveA
End If

End Function
Nov 12 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Sat, 22 Nov 2003 17:14:45 -0000, David B wrote:
...
Call Shell(sWinZip & " -a " & sZipFile & " " & sFileToZip, vbHide)
Name sZipFile As "A:\" & sZipFileName


I guess this is what's causing the error, is it? The shell is running in a
separate process and not reporting back when it's finished.

Use ShellWait instead:
http://www.mvps.org/access/api/api0004.htm

HTH - Peter

--
No mails please.
Nov 12 '05 #2

P: n/a
David,
The file is just not there yet at the time the code wants to rename the file.
Try a msgbox after you're done with zipping.

BTW: Why do you need the scripting-code ?
Wouldn't Filecopy from Access do the same?
--
Hope this helps
Arno R

"David B" <da***@marleycotenospam.fsnet.co.uk> schreef in bericht
news:bp**********@newsg3.svr.pol.co.uk...
I have this code to find a file, place it in C:\ temp, zip it up then send it
to floppy in drive A:\.

When I run it it comes up with error 53 - source file not found. However it
gets as far as putting the file and the zipped file into C:\ temp.

Any thoughts on what is causing this ?
David B
Hexham UK


Public Function BackupAndZipitToDriveA()
On Error GoTo Err_BackupAndZipitToDriveA

'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:\Data\adata\Stock record\Hoofprint\"
sSourceFile = "Stock _be.mdb"

If Dir("C:\Temp", vbDirectory) = "" Then MkDir ("C:\Temp")
sBackupPath = "C:\Temp\"
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 = "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)
Name sZipFile As "A:\" & sZipFileName
Beep
MsgBox "Backup was successful and saved @ " & Chr(13) & Chr(13) & "A:\" &
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)

Exit_BackupAndZipitToDriveA:
Exit Function

Err_BackupAndZipitToDriveA:
If Err = 5 Then 'Invalid procedure call or argument
Beep
MsgBox "Disk is full! Can not move the zip file to the A:\ drive.
Please move the " & sZipFile & " file to a safe location." & vbNewLine &
vbNewLine & sSourceFile, vbCritical
If Dir(sBackupPath & sBackupFile) <> "" Then Kill (sBackupPath &
sBackupFile)
Exit Function
ElseIf Err = 53 Then 'File not found
Beep
MsgBox "Source file can not be found!" & vbNewLine & vbNewLine &
sSourceFile, vbCritical
Exit Function
ElseIf Err = -2147024784 Then 'Method 'CopyFile' of object 'IFileSystem3'
faild
Beep
MsgBox "File is to large to be zipped onto the A:\ drive!" & vbNewLine &
vbNewLine & sSourceFile, vbCritical
Exit Function
Else
MsgBox Err.Number & " - " & Err.Description
Resume Exit_BackupAndZipitToDriveA
End If

End Function

Nov 12 '05 #3

P: n/a
I am using this to copy a b_e file from the front end.
I think ?? that filecopy would give an error message used in this situation
David B

Arno R <ar****************@tiscali.nl> wrote in message
news:3f**********************@dreader2.news.tiscal i.nl...
David,
The file is just not there yet at the time the code wants to rename the file.
Try a msgbox after you're done with zipping.

BTW: Why do you need the scripting-code ?
Wouldn't Filecopy from Access do the same?
--
Hope this helps
Arno R

"David B" <da***@marleycotenospam.fsnet.co.uk> schreef in bericht
news:bp**********@newsg3.svr.pol.co.uk...
I have this code to find a file, place it in C:\ temp, zip it up then send it to floppy in drive A:\.

When I run it it comes up with error 53 - source file not found. However it
gets as far as putting the file and the zipped file into C:\ temp.

Any thoughts on what is causing this ?
David B
Hexham UK


Public Function BackupAndZipitToDriveA()
On Error GoTo Err_BackupAndZipitToDriveA

'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:\Data\adata\Stock record\Hoofprint\"
sSourceFile = "Stock _be.mdb"

If Dir("C:\Temp", vbDirectory) = "" Then MkDir ("C:\Temp")
sBackupPath = "C:\Temp\"
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 = "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)
Name sZipFile As "A:\" & sZipFileName
Beep
MsgBox "Backup was successful and saved @ " & Chr(13) & Chr(13) & "A:\" &
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)
Exit_BackupAndZipitToDriveA:
Exit Function

Err_BackupAndZipitToDriveA:
If Err = 5 Then 'Invalid procedure call or argument
Beep
MsgBox "Disk is full! Can not move the zip file to the A:\ drive.
Please move the " & sZipFile & " file to a safe location." & vbNewLine &
vbNewLine & sSourceFile, vbCritical
If Dir(sBackupPath & sBackupFile) <> "" Then Kill (sBackupPath &
sBackupFile)
Exit Function
ElseIf Err = 53 Then 'File not found
Beep
MsgBox "Source file can not be found!" & vbNewLine & vbNewLine &
sSourceFile, vbCritical
Exit Function
ElseIf Err = -2147024784 Then 'Method 'CopyFile' of object 'IFileSystem3' faild
Beep
MsgBox "File is to large to be zipped onto the A:\ drive!" & vbNewLine & vbNewLine & sSourceFile, vbCritical
Exit Function
Else
MsgBox Err.Number & " - " & Err.Description
Resume Exit_BackupAndZipitToDriveA
End If

End Function



Nov 12 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.