using peazip in an access program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • CD Tom
    Contributor
    • Feb 2009
    • 495

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

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32633

      #32
      Fair dos.

      Can you post what you have for the class khZipFile please.

      Comment

      • CD Tom
        Contributor
        • Feb 2009
        • 495

        #33
        Ok, here's where it starts:
        Code:
        Dim mzipfile As khZip
            Dim StrSavePath, StrZipDir As String
        Set mzipfile = New khZip
        With mzipfile
        'zip chosen files
        .ZipFilePath = strfoldername + "\" & MyZipFileName
        .ZipFiles.Add strfoldername + "\extractcat.csv"
        .ZipFiles.Add strfoldername + "\extractdata.csv"
        .ZipFiles.Add strfoldername + "\extractparm.csv"
        .Zip
        End With
        Here is the modules khZip
        Code:
        '---------------------------------------------------------------------------------------
        ' Module    : khZip
        ' DateTime  : 5/18/2007 14:02
        ' Author    : Ken Jensen
        ' Purpose   : Automate the Windows XP zip functionality
        '---------------------------------------------------------------------------------------
        Option Compare Database
        Option Explicit
        Private Const ERRSOURCE As String = "Zip"
        
        Private mobjZipFile As khZipFiles
        Private mstrZipFilePath As String
        Private mstrUnzipFolderPath As String
        Private mstrZipFolderPath As String
        Private mstrZipFilePath_Temp As String
        
        Public Property Get ZipFilePath() As String
            ZipFilePath = mstrZipFilePath
        End Property
        
        Public Property Let ZipFilePath(strZipFilePathIn As String)
            mstrZipFilePath = strZipFilePathIn
        End Property
        
        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
        
        End Sub
        
        Public Sub Zip()
        
            On Error GoTo Err_Zip
        
            Dim objShell As Object
            Dim objFolder As Object
        
            Dim lngCnt As Long
        
            If IsNull(Me.ZipFilePath) Then
                MsgBox "You must include a path for the zip file", vbOKOnly + vbExclamation
            Else
                If mobjZipFile.Count < 1 Then
                    MsgBox "You must include at least one file to be zipped", vbOKOnly + vbExclamation
                Else
                    NewZip Me.ZipFilePath
        
                    Set objShell = CreateObject("Shell.Application")
                    Set objFolder = objShell.NameSpace(Me.ZipFilePath)
        
                    For lngCnt = 1 To mobjZipFile.Count
                        objFolder.CopyHere mobjZipFile.ZipFileString(lngCnt)
                    Next lngCnt
        
                    'Keep script waiting until Compressing is done
                    On Error Resume Next
                    Do Until objFolder.Items.Count = lngCnt - 1
                        DoEvents
                    Loop
        
                    On Error GoTo Err_Zip
                End If
            End If
        
        Exit_Zip:
            Set objShell = Nothing
            Set objFolder = Nothing
            Exit Sub
        
        Err_Zip:
            Err.Raise Err.Number, Err.Source & " - khZip - Zip " & Erl, Err.Description
            Resume Exit_Zip
        
        End Sub
        
        Public Sub UnZipAll()
        
            On Error GoTo Err_UnZipAll
        
            Dim objShell As Object
        
            Set objShell = CreateObject("Shell.Application")
        
            objShell.NameSpace(Me.UnzipFolderPath).CopyHere objShell.NameSpace(Me.ZipFilePath).Items
        
        Exit_UnZipAll:
            Set objShell = Nothing
            Exit Sub
        
        Err_UnZipAll:
            Err.Raise Err.Number, Err.Source & " - khZip - UnZipAll " & Erl, Err.Description
            Resume Exit_UnZipAll
        
        End Sub
        
        Public Sub ZipAll()
        
            On Error GoTo Err_ZipAll
        
            Dim objShell As Object
            Dim objFolder As Object
            Dim objFolder2 As Object
            Dim tmpFolder As String
        
            If IsNull(Me.ZipFilePath) Then
                MsgBox "You must include a path for the zip file", vbOKOnly + vbExclamation
            Else
                'create temp file then move after zipping
                'issue when try to zip all files in folder if zip file is placed in same folder
        
        
                tmpFolder = "C:\Temp" & "\"
        
                If Dir(tmpFolder) = "" Then
                    On Error Resume Next
                    MkDir tmpFolder
                End If
                On Error GoTo Err_ZipAll
        
                Me.ZipFilePath_Temp = "C:\Temp\" & Right$(Me.ZipFilePath, Len(Me.ZipFilePath) - InStrRev(Me.ZipFilePath, "\"))
        
                NewZip Me.ZipFilePath_Temp
        
                If Right$(Me.ZipFolderPath, 1) <> "\" Then
                    Me.ZipFolderPath = Me.ZipFolderPath & "\"
                End If
        
                Set objShell = CreateObject("Shell.Application")
                Set objFolder = objShell.NameSpace(Me.ZipFilePath_Temp)
                Set objFolder2 = objShell.NameSpace(Me.ZipFolderPath)
        
                objFolder.CopyHere objFolder2.Items
        
                'Keep script waiting until Compressing is done
                On Error Resume Next
                Do Until objFolder.Items.Count = objFolder2.Items.Count
                    DoEvents
                Loop
        
                On Error GoTo Err_ZipAll
        
                If Len(Dir(Me.ZipFilePath)) > 0 Then
                    Kill Me.ZipFilePath
                End If
                Name Me.ZipFilePath_Temp As Me.ZipFilePath
            End If
        
        Exit_ZipAll:
            Set objShell = Nothing
            Set objFolder = Nothing
            Set objFolder2 = Nothing
            Exit Sub
        
        Err_ZipAll:
            Err.Raise Err.Number, Err.Source & " - khZip - ZipAll " & Erl, Err.Description
            Resume Exit_ZipAll
        
        End Sub
        Public Property Get ZipFiles() As khZipFiles
            Set ZipFiles = mobjZipFile
        End Property
        
        Private Sub Class_Terminate()
            On Error Resume Next
            Set mobjZipFile = Nothing
        End Sub
        
        Public Property Get UnzipFolderPath() As String
            UnzipFolderPath = mstrUnzipFolderPath
        End Property
        
        Public Property Let UnzipFolderPath(strUnzipFolderPathIn As String)
            mstrUnzipFolderPath = strUnzipFolderPathIn
        End Property
        
        Public Property Get ZipFolderPath() As String
            ZipFolderPath = mstrZipFolderPath
        End Property
        
        Public Property Let ZipFolderPath(strZipFolderPathIn As String)
            mstrZipFolderPath = strZipFolderPathIn
        End Property
        
        Friend Property Get ZipFilePath_Temp() As String
            ZipFilePath_Temp = mstrZipFilePath_Temp
        End Property
        
        Friend Property Let ZipFilePath_Temp(strZipFilePath_TempIn As String)
            mstrZipFilePath_Temp = strZipFilePath_TempIn
        End Property
        and the module khZipFile
        Code:
        '---------------------------------------------------------------------------------------
        ' Module    : khZipFile
        ' DateTime  : 5/18/2007 14:02
        ' Author    : Ken Jensen
        ' Purpose   : Automate the Windows XP zip functionality
        '---------------------------------------------------------------------------------------
        Option Compare Database
        Option Explicit
        
        Private Const ERRSOURCE As String = "ZipFile"
        Private mstrName As String
        
        Public Property Get Name() As String
            Name = mstrName
        End Property
        
        Public Property Let Name(strNameIn As String)
            mstrName = strNameIn
        End Property
        and module khZipFiles
        Code:
        '---------------------------------------------------------------------------------------
        ' Module    : khZipFiles
        ' DateTime  : 5/18/2007 14:02
        ' Author    : Ken Jensen
        ' Purpose   : Automate the Windows XP zip functionality
        '---------------------------------------------------------------------------------------
        Option Compare Database
        Option Explicit
        
        Private Const ERRSOURCE As String = "ZipFile"
        Private mcln As Collection
        
        Public Function Add(strName) As khZipFile
        
        Dim r As khZipFile
        
            On Error GoTo Err_Add
        
            Set r = New khZipFile
        
            r.Name = strName
            mcln.Add r, strName
        
            Set Add = r
        
        Exit_Add:
            Set r = Nothing
            Exit Function
        
        Err_Add:
            Err.Raise Err.Number, Err.Source & "-" & ERRSOURCE, Err.Description
            Resume Exit_Add
        
        End Function
        
        Private Sub Class_Initialize()
            Set mcln = New Collection
        End Sub
        
        Public Property Get Count()
            Count = mcln.Count
        End Property
        
        Public Function Remove(strName As String)
            mcln.Remove strName
        End Function
        
        Public Property Get Item(strName) As khZipFile
            Set Item = mcln(strName)
        End Property
        
        Private Sub Class_Terminate()
            Set mcln = Nothing
        End Sub
        
        Friend Function ZipFileString(lngCount As Long) As String
            ZipFileString = mcln(lngCount).Name
        End Function
        Hopefully I did this correctly. Let me know if you need anything else.

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32633

          #34
          Originally posted by CD Tom
          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.

          Comment

          • CD Tom
            Contributor
            • Feb 2009
            • 495

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

            Comment

            • NeoPa
              Recognized Expert Moderator MVP
              • Oct 2006
              • 32633

              #36
              Originally posted by Tom
              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 :
              Code:
              Private Sub Class_Initialize()
                  'Nothing required in here as it's just a dummy.
              End Sub

              Comment

              • CD Tom
                Contributor
                • Feb 2009
                • 495

                #37
                I added that to the khZipfile but still get the same error.

                Comment

                • NeoPa
                  Recognized Expert Moderator MVP
                  • Oct 2006
                  • 32633

                  #38
                  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)?

                  Comment

                  • CD Tom
                    Contributor
                    • Feb 2009
                    • 495

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

                    Comment

                    • CD Tom
                      Contributor
                      • Feb 2009
                      • 495

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

                      Comment

                      • NeoPa
                        Recognized Expert Moderator MVP
                        • Oct 2006
                        • 32633

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

                        Comment

                        Working...