• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 669
  • Last Modified:

Add to zip

Hi !
I need to generate a zip file of a database, using the built-in windows XP zip utility. Once this is done, I need to start an outlook session of the user and add the zip file as an attachment. How can I do this by code ?
Thanks
0
ee can
Asked:
ee can
  • 9
  • 7
  • 3
  • +1
1 Solution
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
I don't think you can automate the builtin Zip utility ... the utility lives in the zipfldr.dll library (in the system32 directory) ... AFAIK, there is no way to use this to automatically Zip files, and a quick search of the newsgroups shows this to be backed up by quite a few MS MVPs ... so I'd assume it's correct.

There are quite a lot of freeware Zip utilities which can be used from the commandline, which you could easily do via a batch file ... would this work for you?

0
 
ee canAuthor Commented:
Well I could use winzip but I don't know if all the users have it installed yet. Anyway I was hoping that the built-in zip feature would work from the commandline. I guess if there is no other alternative, winzip would do.
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Note also that you'll need the commandline version of WinZip, and there are some restrictions on how it can be deployed ... basically, it appears that every user would need to have a licensed copy of the WinZip commandline addon:

http://www.winzip.com/downcl.htm

There are other freeware zip alternatives; Tony Toews site has a pretty good listing: http://www.granite.ab.ca/access/compression.htm
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Leigh PurvisDatabase DeveloperCommented:
Hi both.
You can certainly execute more control when using WinZip's commandline support version.
But Winzip out of the box also offers command line instructions.
For example you could try something like

shell "C:\Program Files\WinZip\WZZIP.exe ""C:\YourZip.zip"" ""C:\FileToAdd.txt"""

Although if you're wanting to then use the new archive file then you might want shell wait I suppose...
http://www.mvps.org/access/api/api0004.htm

And, if required, could determine Winzip's install path either from the registry or using
http://www.mvps.org/access/api/api0023.htm
0
 
rockiroadsCommented:
Command line is the easiest way to go
Back in the DOS days there was pkzip,
But if u use command like, I would stick to Winzip like LSMConsulting and LPurvis has suggested
Depending on how big the files are likely to be I would suggest u use Shell and Wait (LPurvis has given u the link to this api004.htm)


If you want to use a third party control (load a ActiveX control - which u can then ship out with your app)

Have a look at Info Zip  http://www.info-zip.org/  (its ftp site for getting files is ftp://ftp.icce.rug.nl/)

Have a look at EclipseUI - free ActiveX - it has compression/decompression features - plus lots more
http://www.greeneclipsesoftware.com/eclipseui.html



0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Good to know - here's a site which describes the command line stuff - note that this says it's undocumented, so no guarantees:

http://www.memecode.com/docs/winzip.html
0
 
ee canAuthor Commented:
Damn Winzip is not installed on my TS profile, I'll let you know asap.
Sorry
0
 
ee canAuthor Commented:
OK it has been installed. I'm running into problems however, here is the code I use :
==========================================================================
        Dim db As Database
        Dim filename As String
        filename = pathstoring & "Prices-" & Trim(Me.cboRegion.Column(1, Me.cboRegion.ListIndex)) & ".mdb"
        If Len(Dir(filename)) > 0 Then
            Kill filename
        End If
        Set db = CreateDatabase(filename, dbLangGeneral, dbVersion40)
        db.Close
        DoCmd.TransferDatabase acExport, "Microsoft Access", filename, acTable, "a", "b"
        DoCmd.TransferDatabase acExport, "Microsoft Access", filename, acTable, "c", "d"
        Shell "C:\Program Files\WinZip\WINZIP32.EXE """ & pathstoring & "YourZip.zip"" """ & filename & """"
        ShellWait (pathstoring & "YourZip.zip")
        MsgBox "Export successful !"
==========================================================================
The Shellwait seems to work but my problem is that when it reaches the winzip command line, winzip opens and pops this message : "Multiple files were dropped, and one or more is an archive. Add files to archive ?". If I say yes, it just promps the regular winzip dialogs....
How to fix this ? I'd like the winzip operation to be silent !
Thanks
0
 
Leigh PurvisDatabase DeveloperCommented:
Do you not kill any existing zip file before creating a new one?
(I assume you're wanting a new archie with nothing in but the file you've just created).
0
 
ee canAuthor Commented:
Yep, I didn't do a kill yet because I didn't think that with that error it would create a zip file. Here is however updated code :
===========================================================================
        Dim db As Database
        Dim filename, filename2 As String
        filename = pathstoring & "Prices-" & Trim(Me.cboRegion.Column(1, Me.cboRegion.ListIndex)) & ".mdb"
        filename2 = pathstoring & "YourZip.zip"
        If Len(Dir(filename)) > 0 Then
            Kill filename
        End If
        Set db = CreateDatabase(filename, dbLangGeneral, dbVersion40)
        db.Close
        DoCmd.TransferDatabase acExport, "Microsoft Access", filename, acTable, "a", "b"
        DoCmd.TransferDatabase acExport, "Microsoft Access", filename, acTable, "c", "d"
        If Len(Dir(filename2)) > 0 Then
            Kill filename2
        End If
        Shell "C:\Program Files\WinZip\WINZIP32.EXE """ & filename2 & """ """ & filename & """"
        ShellWait (filename2)
        'MsgBox filename & vbCrLf & filename2
        MsgBox "Export successful !"
===========================================================================
Now I have error 53, cannot find the specified file....
"C:\Program Files\WinZip\WINZIP32.EXE" is valid, filename2 returns U:\YourZip.zip and filename returns U:\Prices.mdb.
I double-checked the paths and they are good, and the mdb exist ! So why am I having this error ??
0
 
Leigh PurvisDatabase DeveloperCommented:
Have you tried just running it from Start>Run or a command line?
"C:\Program Files\WinZip\WINZIP32.EXE" "U:\YourZip.zip" "U:\Prices.mdb"

Is it definately WINZIP32.EXE and not WZZIP.exe
0
 
ee canAuthor Commented:
OK now I have the same error as before : "Multiple files were dropped, and one or more is an archive. Add files to archive ?" Even when I launch the command from Start/Run. I don't have WZZIP.exe....only WINZIP32.EXE. The only other exe I have are WZQKPICK.EXE and WZSEPE32.EXE.
Any ideas ?
0
 
Leigh PurvisDatabase DeveloperCommented:
Try this

Shell "C:\Program Files\WinZip\WINZIP32.EXE""  -a -ex  """ & filename2 & """ """ & filename & """"
0
 
ee canAuthor Commented:
I tried it in Start/Run it says No files were found for this action that match your criteria - nothing to do (U:\YourZip.zip). Seems like I need to create the zip file before ?!
Thanks
0
 
Leigh PurvisDatabase DeveloperCommented:
If you run

"C:\Program Files\WinZip\WINZIP32.EXE" -a -ex "U:\YourZip.zip" "U:\Prices.mdb"

Does it work?
0
 
ee canAuthor Commented:
In my previous post I explained this is what I actually tried...
0
 
Leigh PurvisDatabase DeveloperCommented:
And you've 100% confirmed that the intended file exists?
You'll only get that error if the intended file to add isn't found.
0
 
ee canAuthor Commented:
I put a break point on this line Shell "C:\Program Files\WinZip\WINZIP32.EXE""  -a -ex  """ & filename2 & """ """ & filename & """" and alt-tab to my windows explorer to see if the mdb exists and it is there...I opened it and both my tables were good.
Good news though when I do this in Start/Run "C:\Program Files\WinZip\WINZIP32.EXE" -a -ex "U:\YourZip.zip" "U:\Prices.mdb" it works now...must have done a type, sorry.
filename returns = U:\Prices.mdb
filename2 returns = U:\YourZip.zip
Is there too much or not enough """" in the shell command ???
Totally clueless here...
0
 
Leigh PurvisDatabase DeveloperCommented:
If that's what you've got then yes - you're missing quotes (or have an extra one - depending on how you look at it).
Try
Shell """C:\Program Files\WinZip\WINZIP32.EXE""  -a -ex  """ & filename2 & """ """ & filename & """"
0
 
ee canAuthor Commented:
Yes, works well now. Thanks
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 9
  • 7
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now