using peazip in an access program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tuxalot
    New Member
    • Feb 2009
    • 200

    #16
    CD Tom:

    This is how I call it:
    Code:
    Dim mzipfile As khZip
    Dim strSavePath, strZipDir As String
    
    strZipDir = BrowseFolder("Next - Choose Folder For Export")
    
    MyZipFileName = <your file name here>
    
    Set mzipfile = New khZip
        With mzipfile
            .ZipFilePath = strZipDir & "\" & MyZipFileName
            'save full path to zip for email purposes
            strSavePath = .ZipFilePath
            .ZipFolderPath = strTempDir
            .ZipAll
        End With
    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:

    Code:
    Option Compare Database
    Option Explicit
    
    '************** Code Start **************
    'This code was originally written by Terry Kreft.
    'It is not to be altered or distributed,
    'except as part of an application.
    'You are free to use it in any application,
    'provided the copyright notice is left unchanged.
    '
    'Code courtesy of
    'Terry Kreft
    
    Private Type BROWSEINFO
        hOwner As Long
        pidlRoot As Long
        pszDisplayName As String
        lpszTitle As String
        ulFlags As Long
        lpfn As Long
        lParam As Long
        iImage As Long
    End Type
    
    Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias _
                                                 "SHGetPathFromIDListA" (ByVal pidl As Long, _
                                                                         ByVal pszPath As String) As Long
    
    Private Declare Function SHBrowseForFolder Lib "shell32.dll" Alias _
                                               "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) _
                                               As Long
    
    Private Const BIF_RETURNONLYFSDIRS = &H1
    Public Function BrowseFolder(szDialogTitle As String) As String
    Dim x As Long, bi As BROWSEINFO, dwIList As Long
    Dim szPath As String, wPos As Integer
    
        With bi
            .hOwner = hWndAccessApp
            .lpszTitle = szDialogTitle
            .ulFlags = BIF_RETURNONLYFSDIRS
        End With
    
        dwIList = SHBrowseForFolder(bi)
        szPath = Space$(512)
        x = SHGetPathFromIDList(ByVal dwIList, ByVal szPath)
    
        If x Then
            wPos = InStr(szPath, Chr(0))
            BrowseFolder = left$(szPath, wPos - 1)
        Else
            BrowseFolder = vbNullString
        End If
    End Function
    '*********** Code End *****************
    And it should work.
    Attached Files
    Last edited by tuxalot; Dec 19 '12, 11:57 PM. Reason: forgot attachment

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32633

      #17
      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 :
      Code:
      'Zip zips up the files in strFiles into strZip.  Returns success state.
      Public Function Zip(strZip As String, strFiles As String) As Boolean
          Dim strCMD As String, strExe As String
      
          Zip = True
          On Error GoTo ErrorZ
          strExe = RegRead(conHKLM, conZipKey, "")
          strCMD = Replace("""%E"" -a+ -ex -ybc ""%Z"" ""%F""", "%E", strExe)
          strCMD = Replace(strCMD, "%Z", strZip)
          strCMD = Replace(strCMD, "%F", strFiles)
          Call Shell(PathName:=strCMD, WindowStyle:=vbNormalFocus)
          Exit Function
      
      ErrorZ:
          strCMD = Replace("Unable to zip {%F} into '%Z'", "%F", strFiles)
          strCMD = Replace(strCMD, "%Z", strZip)
          Call ShowMsg(strMsg:=strCMD, strTitle:="Zip", intButtons:=vbInformation)
          Zip = False
      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) :
      Code:
      Option Compare Database
      Option Explicit
      
      'Windows API Variable Prefixes
      'cb = Count of Bytes (32-bit)
      'w  = Word (16-bit)
      'dw = Double Word (32-bit)
      'lp = Long Pointer (32-bit)
      'b  = Boolean (32-bit)
      'h  = Handle (32-bit)
      'ul = Unsigned Long (32-bit)
      
      Public Const conHKLM = &H80000002
      Public Const REG_NONE As Long = 0               'None
      Public Const REG_SZ As Long = 1                 'Null terminated string
      Public Const REG_EXPAND_SZ As Long = 2          'As above but contains
                                                      '  unexpanded Env Vars
      Public Const REG_BINARY As Long = 3             'binary data
      Public Const REG_DWORD As Long = 4              'Double Word (Long)
      Public Const REG_DWORD_BIG_ENDIAN As Long = 5   'As above but reversed
      Public Const REG_LINK As Long = 6               'Unicode symbolic link
      Public Const REG_MULTI_SZ As Long = 7           'Array of SZs (dbl null ends)
      Public Const REG_RESOURCE_LIST As Long = 8
      Public Const REG_FULL_RESOURCE_DESCRIPTOR As Long = 9
      Public Const REG_RESOURCE_REQUIREMENTS_LIST As Long = 10
      Public Const REG_QWORD As Long = 11             ' Quad Word
      Public Const conStandardRightsAll = &H1F0000
      Public Const conReadControl = &H20000
      Public Const conStandardRightsRead = (conReadControl)
      Public Const conRegSz = 1
      Public Const conOK = 0&
      Public Const conKeyQueryValue = &H1
      Public Const conKeySetValue = &H2
      Public Const conKeyCreateSubKey = &H4
      Public Const conKeyEnumerateSubKeys = &H8
      Public Const conKeyNotify = &H10
      Public Const conKeyCreateLink = &H20
      Public Const conSynchronise = &H100000
      Public Const conRegOptionNonVolatile = 0
      Public Const conKeyAllAccess = ((conStandardRightsAll _
                                    Or conKeyQueryValue _
                                    Or conKeySetValue _
                                    Or conKeyCreateSubKey _
                                    Or conKeyEnumerateSubKeys _
                                    Or conKeyNotify _
                                    Or conKeyCreateLink) _
                                  And (Not conSynchronise))
      Public Const conKeyRead = ((conReadControl _
                               Or conKeyQueryValue _
                               Or conKeyEnumerateSubKeys _
                               Or conKeyNotify) _
                             And (Not conSynchronise))
      
      Private Declare Function RegOpenKeyEx Lib "advapi32.dll" _
          Alias "RegOpenKeyExA" (ByVal hKey As Long, _
                                 ByVal lpSubKey As String, _
                                 ByVal ulOptions As Long, _
                                 ByVal samDesired As Long, _
                                 phkResult As Long) As Long
      Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) _
                                   As Long
      Private Declare Function RegQueryValueExStr Lib "advapi32.dll" _
          Alias "RegQueryValueExA" (ByVal hKey As Long, _
                                    ByVal lpValueName As String, _
                                    ByVal lpReserved As Long, _
                                    ByRef lpType As Long, _
                                    ByVal lpData As String, _
                                    ByRef lpcbData As Long) As Long
      
      Public Function RegRead(ByVal lngHive As Long, _
                              ByVal strKey As String, _
                              ByVal strValue As String) As Variant
          Dim intX As Integer
          Dim strBuf As String
          Dim lngRet As Long, lngHKey As Long, lngType As Long, lngBufLen As Long
      
          RegRead = Null
          strKey = strKey & vbNullChar
          lngRet = RegOpenKeyEx(hKey:=lngHive, _
                                lpSubKey:=strKey, _
                                ulOptions:=0, _
                                samDesired:=conKeyRead, _
                                phkResult:=lngHKey)
          If lngRet = conOK Then
              'Set up buffer to store value
              lngBufLen = 255
              strBuf = String(lngBufLen, 0)
              strValue = strValue & vbNullChar
              lngRet = RegQueryValueExStr(hKey:=lngHKey, _
                                          lpValueName:=strValue, _
                                          lpReserved:=0&, _
                                          lpType:=lngType, _
                                          lpData:=strBuf, _
                                          lpcbData:=lngBufLen)
              'Close key
              Call RegCloseKey(lngHKey)
              Select Case lngType
              Case REG_SZ, REG_EXPAND_SZ, REG_MULTI_SZ, REG_BINARY
                  If lngBufLen = 255 Then
                      RegRead = Null
                  Else
                      If lngType <> REG_BINARY Then lngBufLen = lngBufLen - 1
                      RegRead = Left(strBuf, lngBufLen)
                      If lngType = REG_MULTI_SZ Then _
                          RegRead = Split(RegRead, vbNullChar)
                  End If
              Case REG_DWORD
                  For intX = 4 To 1 Step -1
                      lngRet = Asc(Mid(strBuf, intX))
                      If intX = 4 Then
                          If (lngRet And &H80) > 0 Then
                              RegRead = &H80000000
                              lngRet = (lngRet And &H7F)
                          Else
                              RegRead = 0
                          End If
                      End If
                      RegRead = RegRead Or (lngRet * 256 ^ (intX - 1))
                  Next intX
              End Select
          End If
      End Function

      Comment

      • zmbd
        Recognized Expert Moderator Expert
        • Mar 2012
        • 5501

        #18
        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?

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32633

          #19
          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.

          Comment

          • zmbd
            Recognized Expert Moderator Expert
            • Mar 2012
            • 5501

            #20
            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.

            Comment

            • NeoPa
              Recognized Expert Moderator MVP
              • Oct 2006
              • 32633

              #21
              Originally posted by Zmbd
              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 :-)

              Comment

              • CD Tom
                Contributor
                • Feb 2009
                • 495

                #22
                Tuxalot,
                Thanks but I still have a problem, When I reach the line
                Code:
                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

                Comment

                • CD Tom
                  Contributor
                  • Feb 2009
                  • 495

                  #23
                  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
                  Code:
                  Set mobjZipFile = New khZipFile
                  it jumps to the err_class_initi alize and then I get the error. Maybe this will help more.

                  Comment

                  • CD Tom
                    Contributor
                    • Feb 2009
                    • 495

                    #24
                    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?

                    Comment

                    • NeoPa
                      Recognized Expert Moderator MVP
                      • Oct 2006
                      • 32633

                      #25
                      Originally posted by CD Tom
                      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 ;-)

                      Comment

                      • CD Tom
                        Contributor
                        • Feb 2009
                        • 495

                        #26
                        Yes you are correct I was thinking about tuxalot zip program and forgot about everybody else that was in on this. Sorry
                        Last edited by NeoPa; Dec 20 '12, 11:12 PM. Reason: No edit - just off-topic reply - :-)

                        Comment

                        • CD Tom
                          Contributor
                          • Feb 2009
                          • 495

                          #27
                          I'm still running into an error Automation error and can't figure out why here's the code
                          Code:
                          Set mzipfile = New khZip
                          With mzipfile
                          .zipFilePath = strfoldername + "\" & MyZipFileName
                          .zipfiles.add strfoldername + "\extractcat.csv"
                          .zipfiles.add strfoldername + "\extractdata.csv"
                          .zipfiles.add strfoldername + "\extractparm.csv
                          .zip
                          End with
                          when code reaches the line 1 it jumps to the khZip code
                          Code:
                          Private Sub Class_Initialize()
                          on error goto err_class_initialize
                          set mobjZipFile = New khZipFile
                          exit_Class_initialize:
                          exit sub
                          err_Class_Initialize:
                          err.raise err.number, err.source & " - ActlZip - Class_initialize " & erl, err.description
                          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

                          Comment

                          • NeoPa
                            Recognized Expert Moderator MVP
                            • Oct 2006
                            • 32633

                            #28
                            You cannot make a call to Class_Initializ e(), from within Class_Initializ e().

                            Line #3 of Class_Initializ e() 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_Initializ e() for New khZipFile, we cannot say exactly what may be going wrong there.
                            Last edited by NeoPa; Dec 26 '12, 04:07 PM. Reason: Noticed my error and added PS.

                            Comment

                            • CD Tom
                              Contributor
                              • Feb 2009
                              • 495

                              #29
                              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.

                              Comment

                              • NeoPa
                                Recognized Expert Moderator MVP
                                • Oct 2006
                                • 32633

                                #30
                                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_Initializ e() 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.

                                Comment

                                Working...