Copy zipped file and unzip

Elmobram22

Registered User.
Local time
Today, 23:23
Joined
Jul 12, 2013
Messages
165
Hi guys,

Just wondering how easy it is to add a button to a form with a function to copy a zipped file to another location and unzip it?

Cheers,

Paul
 
I've managed the copy aspect fine but am struggling a bit unzipping the file. Its a bunch of folders with files inside. Don't know whether that makes a difference? When I try the standard unzip method it says bad end of statement.

Private Sub Command47_Click()

FileCopy "c:\users\paul\desktop\zip\WSRP.zip", "c:\users\paul\desktop\zip\WSRP " & [ResID] & " " & [FirstName] & " " & [LastName] & ".zip"

'unzip all zipped files in folder
Dim FolderPath As String, AllZip As String
FolderPath = "c:\users\paul\desktop\zip\" 'folder containing zip files
AllZip = Dir(FolderPath & "\*.zip")
Do While AllZip <> ""
Call Unzip(FolderPath & "\", FolderPath & "\" & AllZip)
AllZip = Dir
Loop
End Sub
 
Where does it come up with that error.?

I've just copied the code and zipped a few folders and it unzips them fine, but I only tried on one zipfile.

Just tried your code and your syntax is incorrect.

The routine expects filename, targetpath, overwrite

The filename has to be the FULL path to the file, so yours would be FolderPath & Allzip
Where are you putting the unzipped files?, give it the path
Decide whether you want to overwrite or not.

Be aware the routine deletes the zipfiles after being processed, so you might want to comment that out for testing.?

HTH
 
So I had a play around and I decided to change the idea. I was hoping to copy a zip file and unzip it in a new location but instead have just opted for copying and folder with files to a new location. Each location is on a local network so it takes a little while to process. I was wondering if there is an easy way to have a processing dialog show while it is doing so. Tried a form with loading on but it didn't work like I wanted. Any ideas?
 
Just one more thing ha... I want to stop the process if the file already exists. What would I have to add to my code for that to happen?

Private Sub Command47_Click()

Dim FSO As Object
Dim FromPath As String
Dim ToPath As String

FromPath = "\\LEIGH\Users\Public\Documents\WSRP"
ToPath = "\\LS-WXLDE3\resident_wsrp\WSRP (" & [FirstName] & " " & [LastName] & " - " & [DobDay] & "-" & [DobMonth] & "-" & [DobYear] & ")"

If Right(FromPath, 1) = "\" Then
FromPath = Left(FromPath, Len(FromPath) - 1)
End If

If Right(ToPath, 1) = "\" Then
ToPath = Left(ToPath, Len(ToPath) - 1)
End If

Set FSO = CreateObject("scripting.filesystemobject")

If FSO.FolderExists(FromPath) = False Then
MsgBox FromPath & " doesn't exist"
Exit Sub

End If

DoCmd.Hourglass True

FSO.CopyFolder Source:=FromPath, Destination:=ToPath

DoCmd.Hourglass False

MsgBox [FirstName] & " " & [LastName] & " now has a Recovery Plan"

DoCmd.Quit

End Sub
 

Users who are viewing this thread

Back
Top Bottom