473,320 Members | 1,910 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

using peazip in an access program

489 256MB
I need to find a free way to zip up some files in my access program. I currently am using winzip but not all customers have winzip. I've found peazip but am having a hard time figuring out the command line prompts. Does anybody know of zip program and can show me the command line or has anybody used peazip and can show me the command line.
Thanks for any help.
Dec 19 '12 #1
40 3390
tuxalot
200 100+
Have a look at basZip by Ken Jensen. It works quite well. Requires four modules:
basZip

(classes)
khZip
khZipFile
khZipFiles
Dec 19 '12 #2
CD Tom
489 256MB
Where do I find basZip I tried a web search but don't get anything.
Dec 19 '12 #3
zmbd
5,501 Expert Mod 4TB
CDTom: Out of curiosity; are you storing the files within the database, not normally a good idea, or is the database compressing files on the user's PC.

You also need to be very aware of the fact that anything you find "free" on the internet may have usage restrictions when applied to your situation. In fact, many either prohibt the use of their product with/within other programs or for commercial usage. All of the pay-for type programs will have such restrictions - they want you to pay for their product.
Dec 19 '12 #4
CD Tom
489 256MB
I'm extracting three .csv files out of the database and then want to zip up those three file so they can be emailed.
Dec 19 '12 #5
tuxalot
200 100+
Here you go. So you will be inserting one standard module and three class modules. Study how this works and if you need assistance let me know. My implementation exports 3 tables as XML to a temp directory, zips them, deletes the individual XML files and emails the zip file. Bytes users helped me get it setup.
Attached Files
File Type: zip Baszip.zip (3.5 KB, 133 views)
Dec 19 '12 #6
CD Tom
489 256MB
I understand that these need to go into my database but for some reason I can figure out how. I've tried creating a new cls module and then importing them in but nothing show up. What am I doing wrong?
Dec 19 '12 #7
tuxalot
200 100+
First you need to unzip your files.

From your VBA editor: click file menu --> import file
From Access 2010 (different in earlier versions): click external data menu, from the import and link panel, select Access. In this screen you want to import, not link to the files. Navigate to your files and select.
Dec 19 '12 #8
CD Tom
489 256MB
I figured out and got them loaded now I need to figure out how to use them. If you can give some code examples I would appreciate it. Thanks
Dec 19 '12 #9
CD Tom
489 256MB
I ran a compile on the program and I get an error on some of the private statements in the khZip
Expand|Select|Wrap|Line Numbers
  1. Private mobjZipFile as khZipFiles
the error I get is User-defined type not defined.
Dec 19 '12 #10
CD Tom
489 256MB
I changed the module name from khZipfile to khZipfiles and that seemed to take care of the error. However now when I run the compile I get another error in the BasZip module when I uncomment the files I get the error Method or data member not found on the .Add in the .ZipFiles any ideas?
Dec 19 '12 #11
CD Tom
489 256MB
I think this was all my error I didn't download all the files you sent sorry about that.
Dec 19 '12 #12
bb80
3
PeaZip is LGPL, so it is free without limitation and unlike GPL can be used both in open or closed source third party works.
In the online help file there are examples of use from command line, and it goes even further as it has a Console tab when you are defining tasks so you can save whatever you are doing to a script.
Dec 19 '12 #13
CD Tom
489 256MB
Ok now that I have this without any errors (sorry about my mess up) How do I run this, I've tried doing a
Expand|Select|Wrap|Line Numbers
  1. call testzip
but it doesn't do anything. Must be something with me as usual.
Dec 19 '12 #14
CD Tom
489 256MB
bb80
I've been working with the Peazip and trying to get it to work. I've created a .bat file to test with but never get and file. The .bat file looks like this
Expand|Select|Wrap|Line Numbers
  1. Start "C:\program files\peazip\peazip.exe -add2zip extractdata.csv extractcat.csv extractparm.csv
I don't get any errors but now .zip file is created. Do you know anything about Peazip the you might be able to help me. I would like to put this into my code but don't know how. Any help would be appreciated.

Thanks
Dec 19 '12 #15
tuxalot
200 100+
CD Tom:

This is how I call it:
Expand|Select|Wrap|Line Numbers
  1. Dim mzipfile As khZip
  2. Dim strSavePath, strZipDir As String
  3.  
  4. strZipDir = BrowseFolder("Next - Choose Folder For Export")
  5.  
  6. MyZipFileName = <your file name here>
  7.  
  8. Set mzipfile = New khZip
  9.     With mzipfile
  10.         .ZipFilePath = strZipDir & "\" & MyZipFileName
  11.         'save full path to zip for email purposes
  12.         strSavePath = .ZipFilePath
  13.         .ZipFolderPath = strTempDir
  14.         .ZipAll
  15.     End With
  16.  
Attached is the BrowseFolder code if you need it. Unzip and import that into a standard module. Then copy/paste this code below into another standard module:

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. '************** Code Start **************
  5. 'This code was originally written by Terry Kreft.
  6. 'It is not to be altered or distributed,
  7. 'except as part of an application.
  8. 'You are free to use it in any application,
  9. 'provided the copyright notice is left unchanged.
  10. '
  11. 'Code courtesy of
  12. 'Terry Kreft
  13.  
  14. Private Type BROWSEINFO
  15.     hOwner As Long
  16.     pidlRoot As Long
  17.     pszDisplayName As String
  18.     lpszTitle As String
  19.     ulFlags As Long
  20.     lpfn As Long
  21.     lParam As Long
  22.     iImage As Long
  23. End Type
  24.  
  25. Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias _
  26.                                              "SHGetPathFromIDListA" (ByVal pidl As Long, _
  27.                                                                      ByVal pszPath As String) As Long
  28.  
  29. Private Declare Function SHBrowseForFolder Lib "shell32.dll" Alias _
  30.                                            "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) _
  31.                                            As Long
  32.  
  33. Private Const BIF_RETURNONLYFSDIRS = &H1
  34. Public Function BrowseFolder(szDialogTitle As String) As String
  35. Dim x As Long, bi As BROWSEINFO, dwIList As Long
  36. Dim szPath As String, wPos As Integer
  37.  
  38.     With bi
  39.         .hOwner = hWndAccessApp
  40.         .lpszTitle = szDialogTitle
  41.         .ulFlags = BIF_RETURNONLYFSDIRS
  42.     End With
  43.  
  44.     dwIList = SHBrowseForFolder(bi)
  45.     szPath = Space$(512)
  46.     x = SHGetPathFromIDList(ByVal dwIList, ByVal szPath)
  47.  
  48.     If x Then
  49.         wPos = InStr(szPath, Chr(0))
  50.         BrowseFolder = left$(szPath, wPos - 1)
  51.     Else
  52.         BrowseFolder = vbNullString
  53.     End If
  54. End Function
  55. '*********** Code End *****************
  56.  
  57.  
And it should work.
Attached Files
File Type: zip basBrowseFiles.zip (3.0 KB, 64 views)
Dec 19 '12 #16
NeoPa
32,556 Expert Mod 16PB
I appreciate you have a preference for PeaZip Tom, but I feel I have to offer the opportunity of using WinZip's command line utility. Principally because it's what I used and can create standard .ZIP files from a command line interface (I expect others can do too, but this is what I set up to use on my systems).

The software needs to be installed to use, but the code that uses it will determine if it's available before calling it. Here's the code I use :
Expand|Select|Wrap|Line Numbers
  1. 'Zip zips up the files in strFiles into strZip.  Returns success state.
  2. Public Function Zip(strZip As String, strFiles As String) As Boolean
  3.     Dim strCMD As String, strExe As String
  4.  
  5.     Zip = True
  6.     On Error GoTo ErrorZ
  7.     strExe = RegRead(conHKLM, conZipKey, "")
  8.     strCMD = Replace("""%E"" -a+ -ex -ybc ""%Z"" ""%F""", "%E", strExe)
  9.     strCMD = Replace(strCMD, "%Z", strZip)
  10.     strCMD = Replace(strCMD, "%F", strFiles)
  11.     Call Shell(PathName:=strCMD, WindowStyle:=vbNormalFocus)
  12.     Exit Function
  13.  
  14. ErrorZ:
  15.     strCMD = Replace("Unable to zip {%F} into '%Z'", "%F", strFiles)
  16.     strCMD = Replace(strCMD, "%Z", strZip)
  17.     Call ShowMsg(strMsg:=strCMD, strTitle:="Zip", intButtons:=vbInformation)
  18.     Zip = False
  19. End Function
RegRead is just one of many such procedures found all over the place, but in case you don't have one here's what I use (Stripped to what's required here) :
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. 'Windows API Variable Prefixes
  5. 'cb = Count of Bytes (32-bit)
  6. 'w  = Word (16-bit)
  7. 'dw = Double Word (32-bit)
  8. 'lp = Long Pointer (32-bit)
  9. 'b  = Boolean (32-bit)
  10. 'h  = Handle (32-bit)
  11. 'ul = Unsigned Long (32-bit)
  12.  
  13. Public Const conHKLM = &H80000002
  14. Public Const REG_NONE As Long = 0               'None
  15. Public Const REG_SZ As Long = 1                 'Null terminated string
  16. Public Const REG_EXPAND_SZ As Long = 2          'As above but contains
  17.                                                 '  unexpanded Env Vars
  18. Public Const REG_BINARY As Long = 3             'binary data
  19. Public Const REG_DWORD As Long = 4              'Double Word (Long)
  20. Public Const REG_DWORD_BIG_ENDIAN As Long = 5   'As above but reversed
  21. Public Const REG_LINK As Long = 6               'Unicode symbolic link
  22. Public Const REG_MULTI_SZ As Long = 7           'Array of SZs (dbl null ends)
  23. Public Const REG_RESOURCE_LIST As Long = 8
  24. Public Const REG_FULL_RESOURCE_DESCRIPTOR As Long = 9
  25. Public Const REG_RESOURCE_REQUIREMENTS_LIST As Long = 10
  26. Public Const REG_QWORD As Long = 11             ' Quad Word
  27. Public Const conStandardRightsAll = &H1F0000
  28. Public Const conReadControl = &H20000
  29. Public Const conStandardRightsRead = (conReadControl)
  30. Public Const conRegSz = 1
  31. Public Const conOK = 0&
  32. Public Const conKeyQueryValue = &H1
  33. Public Const conKeySetValue = &H2
  34. Public Const conKeyCreateSubKey = &H4
  35. Public Const conKeyEnumerateSubKeys = &H8
  36. Public Const conKeyNotify = &H10
  37. Public Const conKeyCreateLink = &H20
  38. Public Const conSynchronise = &H100000
  39. Public Const conRegOptionNonVolatile = 0
  40. Public Const conKeyAllAccess = ((conStandardRightsAll _
  41.                               Or conKeyQueryValue _
  42.                               Or conKeySetValue _
  43.                               Or conKeyCreateSubKey _
  44.                               Or conKeyEnumerateSubKeys _
  45.                               Or conKeyNotify _
  46.                               Or conKeyCreateLink) _
  47.                             And (Not conSynchronise))
  48. Public Const conKeyRead = ((conReadControl _
  49.                          Or conKeyQueryValue _
  50.                          Or conKeyEnumerateSubKeys _
  51.                          Or conKeyNotify) _
  52.                        And (Not conSynchronise))
  53.  
  54. Private Declare Function RegOpenKeyEx Lib "advapi32.dll" _
  55.     Alias "RegOpenKeyExA" (ByVal hKey As Long, _
  56.                            ByVal lpSubKey As String, _
  57.                            ByVal ulOptions As Long, _
  58.                            ByVal samDesired As Long, _
  59.                            phkResult As Long) As Long
  60. Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) _
  61.                              As Long
  62. Private Declare Function RegQueryValueExStr Lib "advapi32.dll" _
  63.     Alias "RegQueryValueExA" (ByVal hKey As Long, _
  64.                               ByVal lpValueName As String, _
  65.                               ByVal lpReserved As Long, _
  66.                               ByRef lpType As Long, _
  67.                               ByVal lpData As String, _
  68.                               ByRef lpcbData As Long) As Long
  69.  
  70. Public Function RegRead(ByVal lngHive As Long, _
  71.                         ByVal strKey As String, _
  72.                         ByVal strValue As String) As Variant
  73.     Dim intX As Integer
  74.     Dim strBuf As String
  75.     Dim lngRet As Long, lngHKey As Long, lngType As Long, lngBufLen As Long
  76.  
  77.     RegRead = Null
  78.     strKey = strKey & vbNullChar
  79.     lngRet = RegOpenKeyEx(hKey:=lngHive, _
  80.                           lpSubKey:=strKey, _
  81.                           ulOptions:=0, _
  82.                           samDesired:=conKeyRead, _
  83.                           phkResult:=lngHKey)
  84.     If lngRet = conOK Then
  85.         'Set up buffer to store value
  86.         lngBufLen = 255
  87.         strBuf = String(lngBufLen, 0)
  88.         strValue = strValue & vbNullChar
  89.         lngRet = RegQueryValueExStr(hKey:=lngHKey, _
  90.                                     lpValueName:=strValue, _
  91.                                     lpReserved:=0&, _
  92.                                     lpType:=lngType, _
  93.                                     lpData:=strBuf, _
  94.                                     lpcbData:=lngBufLen)
  95.         'Close key
  96.         Call RegCloseKey(lngHKey)
  97.         Select Case lngType
  98.         Case REG_SZ, REG_EXPAND_SZ, REG_MULTI_SZ, REG_BINARY
  99.             If lngBufLen = 255 Then
  100.                 RegRead = Null
  101.             Else
  102.                 If lngType <> REG_BINARY Then lngBufLen = lngBufLen - 1
  103.                 RegRead = Left(strBuf, lngBufLen)
  104.                 If lngType = REG_MULTI_SZ Then _
  105.                     RegRead = Split(RegRead, vbNullChar)
  106.             End If
  107.         Case REG_DWORD
  108.             For intX = 4 To 1 Step -1
  109.                 lngRet = Asc(Mid(strBuf, intX))
  110.                 If intX = 4 Then
  111.                     If (lngRet And &H80) > 0 Then
  112.                         RegRead = &H80000000
  113.                         lngRet = (lngRet And &H7F)
  114.                     Else
  115.                         RegRead = 0
  116.                     End If
  117.                 End If
  118.                 RegRead = RegRead Or (lngRet * 256 ^ (intX - 1))
  119.             Next intX
  120.         End Select
  121.     End If
  122. End Function
Dec 20 '12 #17
zmbd
5,501 Expert Mod 4TB
Since WinXP - zip files using the deflate compression have been native to the OS as compressed folders. Isn't there an API call (honestly, I don't know - just curious) that we could use to create and manipulate "compressed" folders?
Dec 20 '12 #18
NeoPa
32,556 Expert Mod 16PB
I don't know either Z :-(

I'm not sure that would answer the requirements of the question though. ZIP files are used outside of Windows, and have been used for many years as a standard for transferring files from one system (person) to another. They have a level of ubiquity (ubiquitousness?) unmatched elsewhere.

While it may not be important for this OP (I don't know), it will still be interesting for many readers to learn about ways of using ZIP files specifically.

NB. That doesn't mean Win compressed files are not interesting or relevant. Just that ZIP files are the main thrust of the question and we need to ensure they are covered fully, even if Win compressed files provide an acceptable alternative for this OP.
Dec 20 '12 #19
zmbd
5,501 Expert Mod 4TB
I understand. The folder/zip-file in WinXP, etc... is still a zip file and therefor shown as such in the file explorers. However, if you double click on the zipfile, you can use it like any other directory (haven't tried mapping a drive to one; however, I don't think that'll work).

IN anycase, if there was an API call to the WIN32 or one of the other DLL that'd allow the creation of the file and subsequent manipulation - that might fullfill OP request.

Something to look into in the near future.
Dec 20 '12 #20
NeoPa
32,556 Expert Mod 16PB
Zmbd:
IN anycase, if there was an API call to the WIN32 or one of the other DLL that'd allow the creation of the file and subsequent manipulation - that might fullfill OP request.
Indeed. I was showing my ignorance it seems :-( If it can create a standard ZIP file, and is relatively easy to accomplish in code, then it would certainly suit both the OP and the main question :-)
Dec 20 '12 #21
CD Tom
489 256MB
Tuxalot,
Thanks but I still have a problem, When I reach the line
Expand|Select|Wrap|Line Numbers
  1. Set mzipfile = New khzip
I get an error automation error. What am I doing wrong.
I do have this working with Winzip but because some users don't have winzip I'm looking for a way where they don't have to purchase it. It looks like tuxalot may have the answer if I can get it to work.
Thanks
Dec 20 '12 #22
CD Tom
489 256MB
tuxalot,
I'll try and give you more details on the error. When it hits the above line it goes to khZip Module to the Private Sub Class_initalize and again when it hits the line
Expand|Select|Wrap|Line Numbers
  1. Set mobjZipFile = New khZipFile
it jumps to the err_class_initialize and then I get the error. Maybe this will help more.
Dec 20 '12 #23
CD Tom
489 256MB
I'm running Windows 7 but some of my users are using Windows XP I guess I should ask does this work in Windows 7?
Dec 20 '12 #24
NeoPa
32,556 Expert Mod 16PB
CD Tom:
I guess I should ask does this work in Windows 7?
When you do, be sure to specify what you mean by this ;-)
Dec 20 '12 #25
CD Tom
489 256MB
Yes you are correct I was thinking about tuxalot zip program and forgot about everybody else that was in on this. Sorry
Dec 20 '12 #26
CD Tom
489 256MB
I'm still running into an error Automation error and can't figure out why here's the code
Expand|Select|Wrap|Line Numbers
  1. Set mzipfile = New khZip
  2. With mzipfile
  3. .zipFilePath = strfoldername + "\" & MyZipFileName
  4. .zipfiles.add strfoldername + "\extractcat.csv"
  5. .zipfiles.add strfoldername + "\extractdata.csv"
  6. .zipfiles.add strfoldername + "\extractparm.csv
  7. .zip
  8. End with
when code reaches the line 1 it jumps to the khZip code
Expand|Select|Wrap|Line Numbers
  1. Private Sub Class_Initialize()
  2. on error goto err_class_initialize
  3. set mobjZipFile = New khZipFile
  4. exit_Class_initialize:
  5. exit sub
  6. err_Class_Initialize:
  7. err.raise err.number, err.source & " - ActlZip - Class_initialize " & erl, err.description
  8. Resume Exit_Class_initialize
code reaches the set statement and jumps to the error and I get the automation error.
Any help would sure be appreciated
Thanks
Hope you had a Merry Christmas
Dec 26 '12 #27
NeoPa
32,556 Expert Mod 16PB
You cannot make a call to Class_Initialize(), from within Class_Initialize().

Line #3 of Class_Initialize() attempts to do this. It's not logical that you should even want to TBF.

PS. I beg your pardon! That is not the case here as one is New khZip while the other is New khZipFile. However, as we have no information pertaining to whether or not you even have a Class_Initialize() for New khZipFile, we cannot say exactly what may be going wrong there.
Dec 26 '12 #28
CD Tom
489 256MB
This is the code the Tuxalot sent me and I'm trying to get it to work. Tuxalot sent me some modules to put into my code to get the zip to work. I've entered this code and when I run it I get the error mentioned. I was trying to get back to Tuxalot and see if he/she could help me.
Dec 26 '12 #29
NeoPa
32,556 Expert Mod 16PB
Well, Tom, that may make sense from your perspective, but there are a lot of things wrong with that approach.

The site, which provides the means for you to get free help when you need it, will not benefit from threads where some of the information is public and some of it not included publicly. In fact it will suffer, as people looking for answers to similar questions try to follow the thread but get lost due to missing information. They leave in disgust and the site is marked down by the SEs (Google etc).

Other experts are already involved in the thread. Unless you feel you have the right to determine who may, and who may not, respond to your questions in a public thread owned by the site, then these experts also deserve the respect of your including all the relevant information required to understand, and therefore help with, your problem.

Please don't think I'm trying to slam you for not perceiving these nuances. I don't expect most members to appreciate some of these niceties, so your not doing so can hardly be criticised. Nevertheless they are true, and we would ask that you bear them in mind and make all relevant information available to the thread as a whole so that all may understand and benefit from the troubles you're experiencing at this time. Others will almost certainly want to benefit from the solutions found in here at later dates. Please understand that this is a moderator request, as full relevant disclosure is a requirement for participating on this site.

A point to bear in mind (and we on the experts side always do) is that any individual expert or helper may go on holiday or be otherwise unavailable for an extended period half way through any number of threads. It does no-one any good if these threads are left in limbo during that time. Now is a particularly likely period through which members may have extended absences.

Line #3 in your Class_Initialize() procedure is clearly where the problem occurs. Without knowing what you have in your project to handle this, no-one will be able to follow the problem. Even Tux can only guess how well you have incorporated the code he made available to you. You certainly wouldn't be the first member to fail to incorporate suggestions, and even code blocks provided for you, incorrectly.
Dec 26 '12 #30
CD Tom
489 256MB
I didn't realize you couldn't answer to an individual. Your explanation makes sense and I will be more careful in the future.
Thanks for the heads up.
Dec 26 '12 #31
NeoPa
32,556 Expert Mod 16PB
Fair dos.

Can you post what you have for the class khZipFile please.
Dec 27 '12 #32
CD Tom
489 256MB
Ok, here's where it starts:
Expand|Select|Wrap|Line Numbers
  1. Dim mzipfile As khZip
  2.     Dim StrSavePath, StrZipDir As String
  3. Set mzipfile = New khZip
  4. With mzipfile
  5. 'zip chosen files
  6. .ZipFilePath = strfoldername + "\" & MyZipFileName
  7. .ZipFiles.Add strfoldername + "\extractcat.csv"
  8. .ZipFiles.Add strfoldername + "\extractdata.csv"
  9. .ZipFiles.Add strfoldername + "\extractparm.csv"
  10. .Zip
  11. End With
  12.  
Here is the modules khZip
Expand|Select|Wrap|Line Numbers
  1. '---------------------------------------------------------------------------------------
  2. ' Module    : khZip
  3. ' DateTime  : 5/18/2007 14:02
  4. ' Author    : Ken Jensen
  5. ' Purpose   : Automate the Windows XP zip functionality
  6. '---------------------------------------------------------------------------------------
  7. Option Compare Database
  8. Option Explicit
  9. Private Const ERRSOURCE As String = "Zip"
  10.  
  11. Private mobjZipFile As khZipFiles
  12. Private mstrZipFilePath As String
  13. Private mstrUnzipFolderPath As String
  14. Private mstrZipFolderPath As String
  15. Private mstrZipFilePath_Temp As String
  16.  
  17. Public Property Get ZipFilePath() As String
  18.     ZipFilePath = mstrZipFilePath
  19. End Property
  20.  
  21. Public Property Let ZipFilePath(strZipFilePathIn As String)
  22.     mstrZipFilePath = strZipFilePathIn
  23. End Property
  24.  
  25. Private Sub Class_Initialize()
  26.  
  27.     On Error GoTo Err_Class_Initialize
  28.  
  29.     Set mobjZipFile = New khZipFile
  30.  
  31. Exit_Class_Initialize:
  32.     Exit Sub
  33.  
  34. Err_Class_Initialize:
  35.     Err.Raise Err.Number, Err.Source & " - ActlZip - Class_Initialize " & Erl, Err.Description
  36.     Resume Exit_Class_Initialize
  37.  
  38. End Sub
  39.  
  40. Public Sub Zip()
  41.  
  42.     On Error GoTo Err_Zip
  43.  
  44.     Dim objShell As Object
  45.     Dim objFolder As Object
  46.  
  47.     Dim lngCnt As Long
  48.  
  49.     If IsNull(Me.ZipFilePath) Then
  50.         MsgBox "You must include a path for the zip file", vbOKOnly + vbExclamation
  51.     Else
  52.         If mobjZipFile.Count < 1 Then
  53.             MsgBox "You must include at least one file to be zipped", vbOKOnly + vbExclamation
  54.         Else
  55.             NewZip Me.ZipFilePath
  56.  
  57.             Set objShell = CreateObject("Shell.Application")
  58.             Set objFolder = objShell.NameSpace(Me.ZipFilePath)
  59.  
  60.             For lngCnt = 1 To mobjZipFile.Count
  61.                 objFolder.CopyHere mobjZipFile.ZipFileString(lngCnt)
  62.             Next lngCnt
  63.  
  64.             'Keep script waiting until Compressing is done
  65.             On Error Resume Next
  66.             Do Until objFolder.Items.Count = lngCnt - 1
  67.                 DoEvents
  68.             Loop
  69.  
  70.             On Error GoTo Err_Zip
  71.         End If
  72.     End If
  73.  
  74. Exit_Zip:
  75.     Set objShell = Nothing
  76.     Set objFolder = Nothing
  77.     Exit Sub
  78.  
  79. Err_Zip:
  80.     Err.Raise Err.Number, Err.Source & " - khZip - Zip " & Erl, Err.Description
  81.     Resume Exit_Zip
  82.  
  83. End Sub
  84.  
  85. Public Sub UnZipAll()
  86.  
  87.     On Error GoTo Err_UnZipAll
  88.  
  89.     Dim objShell As Object
  90.  
  91.     Set objShell = CreateObject("Shell.Application")
  92.  
  93.     objShell.NameSpace(Me.UnzipFolderPath).CopyHere objShell.NameSpace(Me.ZipFilePath).Items
  94.  
  95. Exit_UnZipAll:
  96.     Set objShell = Nothing
  97.     Exit Sub
  98.  
  99. Err_UnZipAll:
  100.     Err.Raise Err.Number, Err.Source & " - khZip - UnZipAll " & Erl, Err.Description
  101.     Resume Exit_UnZipAll
  102.  
  103. End Sub
  104.  
  105. Public Sub ZipAll()
  106.  
  107.     On Error GoTo Err_ZipAll
  108.  
  109.     Dim objShell As Object
  110.     Dim objFolder As Object
  111.     Dim objFolder2 As Object
  112.     Dim tmpFolder As String
  113.  
  114.     If IsNull(Me.ZipFilePath) Then
  115.         MsgBox "You must include a path for the zip file", vbOKOnly + vbExclamation
  116.     Else
  117.         'create temp file then move after zipping
  118.         'issue when try to zip all files in folder if zip file is placed in same folder
  119.  
  120.  
  121.         tmpFolder = "C:\Temp" & "\"
  122.  
  123.         If Dir(tmpFolder) = "" Then
  124.             On Error Resume Next
  125.             MkDir tmpFolder
  126.         End If
  127.         On Error GoTo Err_ZipAll
  128.  
  129.         Me.ZipFilePath_Temp = "C:\Temp\" & Right$(Me.ZipFilePath, Len(Me.ZipFilePath) - InStrRev(Me.ZipFilePath, "\"))
  130.  
  131.         NewZip Me.ZipFilePath_Temp
  132.  
  133.         If Right$(Me.ZipFolderPath, 1) <> "\" Then
  134.             Me.ZipFolderPath = Me.ZipFolderPath & "\"
  135.         End If
  136.  
  137.         Set objShell = CreateObject("Shell.Application")
  138.         Set objFolder = objShell.NameSpace(Me.ZipFilePath_Temp)
  139.         Set objFolder2 = objShell.NameSpace(Me.ZipFolderPath)
  140.  
  141.         objFolder.CopyHere objFolder2.Items
  142.  
  143.         'Keep script waiting until Compressing is done
  144.         On Error Resume Next
  145.         Do Until objFolder.Items.Count = objFolder2.Items.Count
  146.             DoEvents
  147.         Loop
  148.  
  149.         On Error GoTo Err_ZipAll
  150.  
  151.         If Len(Dir(Me.ZipFilePath)) > 0 Then
  152.             Kill Me.ZipFilePath
  153.         End If
  154.         Name Me.ZipFilePath_Temp As Me.ZipFilePath
  155.     End If
  156.  
  157. Exit_ZipAll:
  158.     Set objShell = Nothing
  159.     Set objFolder = Nothing
  160.     Set objFolder2 = Nothing
  161.     Exit Sub
  162.  
  163. Err_ZipAll:
  164.     Err.Raise Err.Number, Err.Source & " - khZip - ZipAll " & Erl, Err.Description
  165.     Resume Exit_ZipAll
  166.  
  167. End Sub
  168. Public Property Get ZipFiles() As khZipFiles
  169.     Set ZipFiles = mobjZipFile
  170. End Property
  171.  
  172. Private Sub Class_Terminate()
  173.     On Error Resume Next
  174.     Set mobjZipFile = Nothing
  175. End Sub
  176.  
  177. Public Property Get UnzipFolderPath() As String
  178.     UnzipFolderPath = mstrUnzipFolderPath
  179. End Property
  180.  
  181. Public Property Let UnzipFolderPath(strUnzipFolderPathIn As String)
  182.     mstrUnzipFolderPath = strUnzipFolderPathIn
  183. End Property
  184.  
  185. Public Property Get ZipFolderPath() As String
  186.     ZipFolderPath = mstrZipFolderPath
  187. End Property
  188.  
  189. Public Property Let ZipFolderPath(strZipFolderPathIn As String)
  190.     mstrZipFolderPath = strZipFolderPathIn
  191. End Property
  192.  
  193. Friend Property Get ZipFilePath_Temp() As String
  194.     ZipFilePath_Temp = mstrZipFilePath_Temp
  195. End Property
  196.  
  197. Friend Property Let ZipFilePath_Temp(strZipFilePath_TempIn As String)
  198.     mstrZipFilePath_Temp = strZipFilePath_TempIn
  199. End Property
  200.  
and the module khZipFile
Expand|Select|Wrap|Line Numbers
  1. '---------------------------------------------------------------------------------------
  2. ' Module    : khZipFile
  3. ' DateTime  : 5/18/2007 14:02
  4. ' Author    : Ken Jensen
  5. ' Purpose   : Automate the Windows XP zip functionality
  6. '---------------------------------------------------------------------------------------
  7. Option Compare Database
  8. Option Explicit
  9.  
  10. Private Const ERRSOURCE As String = "ZipFile"
  11. Private mstrName As String
  12.  
  13. Public Property Get Name() As String
  14.     Name = mstrName
  15. End Property
  16.  
  17. Public Property Let Name(strNameIn As String)
  18.     mstrName = strNameIn
  19. End Property
  20.  
and module khZipFiles
Expand|Select|Wrap|Line Numbers
  1. '---------------------------------------------------------------------------------------
  2. ' Module    : khZipFiles
  3. ' DateTime  : 5/18/2007 14:02
  4. ' Author    : Ken Jensen
  5. ' Purpose   : Automate the Windows XP zip functionality
  6. '---------------------------------------------------------------------------------------
  7. Option Compare Database
  8. Option Explicit
  9.  
  10. Private Const ERRSOURCE As String = "ZipFile"
  11. Private mcln As Collection
  12.  
  13. Public Function Add(strName) As khZipFile
  14.  
  15. Dim r As khZipFile
  16.  
  17.     On Error GoTo Err_Add
  18.  
  19.     Set r = New khZipFile
  20.  
  21.     r.Name = strName
  22.     mcln.Add r, strName
  23.  
  24.     Set Add = r
  25.  
  26. Exit_Add:
  27.     Set r = Nothing
  28.     Exit Function
  29.  
  30. Err_Add:
  31.     Err.Raise Err.Number, Err.Source & "-" & ERRSOURCE, Err.Description
  32.     Resume Exit_Add
  33.  
  34. End Function
  35.  
  36. Private Sub Class_Initialize()
  37.     Set mcln = New Collection
  38. End Sub
  39.  
  40. Public Property Get Count()
  41.     Count = mcln.Count
  42. End Property
  43.  
  44. Public Function Remove(strName As String)
  45.     mcln.Remove strName
  46. End Function
  47.  
  48. Public Property Get Item(strName) As khZipFile
  49.     Set Item = mcln(strName)
  50. End Property
  51.  
  52. Private Sub Class_Terminate()
  53.     Set mcln = Nothing
  54. End Sub
  55.  
  56. Friend Function ZipFileString(lngCount As Long) As String
  57.     ZipFileString = mcln(lngCount).Name
  58. End Function
  59.  
  60.  
Hopefully I did this correctly. Let me know if you need anything else.
Dec 27 '12 #33
NeoPa
32,556 Expert Mod 16PB
CD Tom:
Hopefully I did this correctly. Let me know if you need anything else.
That looks like a perfect job Tom.

I'm assuming that line #29 of khZip is the one that triggers the error when you run it?

This leaves me somewhat confused. I was under the impression that class _Initialize() procedures were optional. The only conceivable 'error' I can see with your khZipFile code is the absence of such a procedure.

The other weird thing is that Error Trapping, which is a VBA Editor General Option, has to be set to 'Break in Class Module' for anything to trigger for line #29 at all. I guess you have that set correctly, and as there is no further code to hit (No _Initialize() procedure for khZipFile.) the error must fire there. Possibly not so weird if that is the issue, but I'm sure such a problem would have come up with Ken's code earlier if that were the issue.

In short, I'm still not sure about that idea, but it may help to test it out by trying with a dummy procedure in place for that class.
Dec 27 '12 #34
CD Tom
489 256MB
I'm not sure where to start, this is new to me and thou I understand most of the code I'm confused about other, so any help is appreciated.
Dec 28 '12 #35
NeoPa
32,556 Expert Mod 16PB
Tom:
I'm not sure where to start, this is new to me
No worries.

You want something like the following to be included in your khZipFile class module :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Class_Initialize()
  2.     'Nothing required in here as it's just a dummy.
  3. End Sub
Dec 28 '12 #36
CD Tom
489 256MB
I added that to the khZipfile but still get the same error.
Dec 28 '12 #37
NeoPa
32,556 Expert Mod 16PB
OK Tom. That didn't help it seems. Please feel free to remove that code now as it only told us that wasn't the problem.

I tried to go back to the error message reported, but it seems you haven't given us much information on this. You've given the where (which line it occurs on) but not the what. What (exactly) is the error message (All we know is that you reported it as 'An error automation error' in post #22)?
Dec 28 '12 #38
CD Tom
489 256MB
Line #35 in the khzip module seems to be where I get the error "automation error" if I comment out that line I get back and continues until line #4 then it jumps to the khzip module line 168, 169 170 then goes back and I get an error Object variable or With block variable not set.
Dec 28 '12 #39
CD Tom
489 256MB
I've decided to give up on this, I've wasted to much of your time and to be truthful this has got me so confused I don't know where to continue. I have the zip working with winzip and I'll just let users know that if they don't have winzip loaded they will manually have to zip up the files with what ever zip program they have. Thanks you for all your work, you guys are great.
Dec 28 '12 #40
NeoPa
32,556 Expert Mod 16PB
No worries Tom.

From your earlier post it seems the error was occurring differently from how I understood it from your earlier comment TBF, so tying it down to the actual problem was always going to be difficult.
Dec 28 '12 #41

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: A P | last post by:
I am planning to migrate my exisiting MS Access program that uses yes/no fields (checkbox). Can ASP identifies checkbox field of ms access? I am planning to use the same database and use msacess...
2
by: Jim | last post by:
I am a FoxPro programmer. What software do I need to program using MS access... I have apps that are non-web standalone and some web based... Do you recommend any learning resources? ...
1
by: Dik van der Zwan | last post by:
I have made a Setup for a ms-access program with the package and deployment wizard of ms-office 2000. When installing my program with the Setup, it will make a shortcut to start the program....
34
by: John Harrison | last post by:
An odd confession; an odd request; but here's the tale.... My company has a few PC systems which we have used for about 7 years and not updated - we've "made do", and besides, "if it ain't...
2
by: Brian Worth | last post by:
I have just upgraded from VB 4.0 to VB .NET 2002. One program under VB 4.0 was able to shut down or restart the (windows XP) machine using a series of API calls. (Getlasterror, GetCurrentProcess,...
7
by: Johnny | last post by:
I am not an expert but I am trying to develope an access program and have hit the following snag: Using the queries in one of the fields there is an inserted amount say 3, now if that amount...
0
by: mroks via AccessMonster.com | last post by:
HELLO GUYS, anyone could help me on how to connect my MS access program to sql server for storage of data. i'll be using sql database instead of built in MS Access database. i have separate...
6
by: Mark | last post by:
Currently using MS Access 2000 and SQL Server Express. Using the current DAO OpenRecordset code listed below, however I keep getting the error message.... 3254: ODBC --Cannot lock all records ...
1
by: ken estes | last post by:
Have an older access program that I loaded to a mass storage device to upload into my laptop (Vista). When I try to initiate the Access program a display comes up saying I need to reformat the older...
3
by: jimatqsi | last post by:
I have a weird problem at a client site. This has popped up in recent months and I don't know if it is because of an update to my development machine or something updated at the client site. I'm...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.