?
Solved

Zip and Unzip MDB files using VB6

Posted on 2006-04-26
7
Medium Priority
?
996 Views
Last Modified: 2012-06-21
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
Comment
Question by:RussellMartin
  • 2
4 Comments
 
LVL 2

Author Comment

by:RussellMartin
ID: 16559982
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
 
LVL 28

Accepted Solution

by:
Ark earned 500 total points
ID: 16570738

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
 
LVL 28

Expert Comment

by:Ark
ID: 16570749
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question