"Comet Developer" <de*******@comet-online.co.za> wrote in message news:<bl**********@ctb-nnrp2.saix.net>...
I would like to compress my Access database from within my VB6 Aplication I
am writing.
Anyone know how?
Bjorn's method requires the user to have Access on their machine, and
Zoltan's method requires you to be using DAO. My method requires none
of those. However, you may want to do some checking to find out what
version of odvccp32.dll the user needs, if everyone has it, what OS's
it's suppported on, etc. In my case, all machines will be Win2k, and
it works fine. I haven't done testing on WinXP.
By the way, I have NO idea where this came from, and I'm sorry to the
original person that I got this from. If anyone knows, please post
the author and I'll be sure to give them credit.
Private Declare Function SQLConfigDataSource Lib "odbccp32.dll" (ByVal
hwnd As Long, ByVal fRequest As Integer, ByVal cDriver As String,
ByVal cAttributes As String) As Boolean
Private Const ODBC_ADD_DSN = 1
Public Function CompactAccess(sDBPath, sNewPath, hSomeHandle As Long)
As Boolean
Dim bResult As Boolean
Dim sDriver As String
Dim sAttribute As String
' ----------------------------------------------------------
sDriver = "Microsoft Access Driver (*.mdb)"
' ----------------------------------------------------------
' ----------------------------------------------------------
' compact database
' ----------------------------------------------------------
sAttribute = "COMPACT_DB=""" & sDBPath & """ """ & sNewPath & """
General"
bResult = SQLConfigDataSource(hSomeHandle, ODBC_ADD_DSN, sDriver,
sAttribute)
' ----------------------------------------------------------
' ----------------------------------------------------------
CompactAccess = bResult
' ----------------------------------------------------------
End Function
And call it like this, from a form in my example:
If CompactAccess(sDBLocalPath, sDBLocalPath, Me.hwnd) = False Then
' Compact didn't work -- what reasons would cause this?
End If