Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access VBA Form code problem with zip files

Status
Not open for further replies.

dssjon

MIS
May 29, 2007
37
US
I need to figure out how to edit this code to work for multiple zip files, not just a single hard coded file. I could call the unzip method multiple times on a list but I can't figure out how to retrieve the file names from a listbox in order to call unzip on the file. Any help out there ? :)

Code:
Sub UnzipSingle()
    Dim FSO As Object
    Dim oApp As Object
    Dim fname
    Dim FileNameFolder
    Dim DefPath As String
    Dim strDate As String

    fname = CurrentProject.Path & "\Files.zip"
    
    If fname = False Then
        'do nothing
    Else
    'Set default path to current database folder
        DefPath = CurrentProject.Path
        If Right(DefPath, 1) <> "\" Then
            DefPath = DefPath & "\"
        End If

        strDate = Format(Now, " dd-mm-yy h-mm-ss")
        FileNameFolder = DefPath & "MyUnzipFolder " & strDate & "\"

        'Create normal folder
        MkDir FileNameFolder

        Set oApp = CreateObject("Shell.Application")
        'Copy the files in the newly created folder
        oApp.NameSpace(FileNameFolder).CopyHere oApp.NameSpace(fname).Items

        MsgBox "You find the files here: " & FileNameFolder
        On Error Resume Next
        Set FSO = CreateObject("scripting.filesystemobject")
        FSO.DeleteFolder Environ("Temp") & "\Temporary Directory*", True

        Set oApp = Nothing
        Set FSO = Nothing
    End If
End Sub
 
you can retrieve data from a listbox using the itemData method...

e.g. listBoxName.ItemData(index)

--------------------
Procrastinate Now!
 

listBoxName.ItemData(index) requires the specific index of the selected listbox item. What about multiple selected file names.How would I go about finding the index of each name in the listbox? and iterating over it. I have an iterate method working, but Im not sure how to tie it into this.


Code:
Sub Iterate()

    Dim ctlList As Control
    Dim varItem As Variant
    Set ctlList = Forms!FileProcessor!List0
    For Each varItem In ctlList.ItemsSelected
       'Unzip
    Next varItem
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top