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

Zip and Unzip MDB files using VB6

Like it says on the tin!

I have a vb6 app which creates an Access MDB file of about 250kb. This file will unltimately be emailed using a slow connection. When zipped, this file is only around 15kb in size. Is there a way I can use Windows compressed folders to zip the file programmaticaly.

I need to use a standard windows API and not a third party dll or control.

Later I have another application that will process this mdb file. It would be good if this app could unzip the file and process the mdb automatically with out user interaction.
0
RussellMartin
Asked:
RussellMartin
  • 2
1 Solution
 
RussellMartinAuthor Commented:
CQUINN, this link requires WinZIP.

I want to tap into Windows Compressed Zip Folders if possible. This will allow my application to not rely on third party software.

Is there an API call or something available for Xp or Windows 2k?
0
 
ArkCommented:

Public Function vbZIP(ByVal sSource As String, ByVal sDest As String) As Boolean
   Dim lAttr As Long, lInitialLength As Long
   lAttr = GetFileAttributes(sSource)
   If lAttr = -1 Then Exit Function
   
   Dim sZipHeader As String
'   sZipHeader = Chr(80) & Chr(75) & Chr(5) & Chr(6) & String(18, Chr(0))
   sZipHeader = "PK" & Chr(5) & Chr(6) & String(18, Chr(0))
   If Dir(sDest) <> "" Then Kill sDest
   Dim nFile As Integer
   nFile = FreeFile
   Open sDest For Output As #nFile
      Print #nFile, sZipHeader
   Close #nFile
   lInitialLength = FileLen(sDest)
   Dim oShell, oSource
   Set oShell = CreateObject("Shell.Application")
  'Copy the file(s) to the compressed folder
   If (lAttr And vbDirectory) = vbDirectory Then
      Set oSource = oShell.NameSpace(CVar(sSource)).Items
   Else
      Set oSource = oShell.NameSpace(CVar(GetParentFolder(sSource))).ParseName(GetFileTitle(sSource))
   End If
   If Not oSource Is Nothing Then
      oShell.NameSpace(CVar(sDest)).CopyHere oSource, &H615
   Else
      GoTo ErrZip
   End If
   Do While Dir(sDest) = ""
      DoEvents
      Sleep 100
   Loop
   On Error Resume Next
   Do While FileLen(sDest) = lInitialLength
      DoEvents
      Sleep 100
   Loop
  'wait for lock to release
   On Error Resume Next
   Do
'Attempt to open the file, this causes an Err 70,
'Permission Denied when the file is already open
      nFile = FreeFile
      Open sDest For Append As #nFile
      Close #nFile
      If Err = 0 Then Exit Do
      Sleep 100
      Err.Clear
   Loop
   vbZIP = True
ErrZip:
   Set oSource = Nothing
   Set oShell = Nothing
End Function

'Using
Call vbZIP("c:\data.mdb", "c:\data.zip")
0
 
ArkCommented:
Oops, forgot API:
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Public Declare Function GetFileAttributes Lib "kernel32" Alias "GetFileAttributesA" (ByVal lpFileName As String) As Long
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now