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.
LVL 2
RussellMartinAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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?
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")

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.