How can I compact an Access MDB file from my VB program without adding DAO or JRO to my project? I want to keep my project as small as possible. I already have included ADO. Is there a JET API call to compact? What is the declaration statement?
I don't know about a Jet API call, but you can compact an Access database through ODBC calls. Check the Access ODBC driver documentation and the ODBC driver API.
Here is an example of compacting an Access Database using JRO:
<%
Option Explicit
Const THEJETVAR= 4
function Squish(thePathDB, boolIs97)
Dim fso, Engine, strThePathDB
strThePathDB = left(thePathDB,instrrev(ThePathDB,"\")
Set fso = CreateObject("Scripting.FileSystemObject"
if fso.FileExists(thePathDB) Then
Set Engine = CreateObject("JRO.JetEngine"
if boolIs97 = "True" Then
Engine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & thePathDB, _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strThePathDB & "temp.mdb;" _
& "Jet OLEDB:Engine Type=" & JET_3X
Else
Engine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & thePathDB, _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strThePathDB & "temp.mdb"
End if
fso.CopyFile strThePathDB & "temp.mdb",thePathDB
fso.DeleteFile(strThePathDB & "temp.mdb"
Set fso = nothing
Set Engine = nothing
Squish = "Your database, " & thePathDB & ", has been Compacted" & vbCrLf
Else
Squish = "The database name or path has Not been found. Try Again" & vbCrLf
End if
End function
%>
<HTML><HEAD><TITLE>Compact Database</TITLE></HEAD><BODY>
<H2 align="center"> Compacting Dealer database</H2>
<P align="center">
<FORM action=compact.asp>
Enter relative path To the database, including database name.<BR><BR>
<INPUT type="text" name="thePathDB" value="/data/dealers.mdb">
<BR><BR>
<INPUT type="checkbox" name="boolIs97" value="True"> Check if Access 97 database
<BR><I> (default is Access 2000)</I><BR><BR>
<INPUT type="submit">
<FORM>
<BR><BR>
<%
Dim thePathDB,boolIs97
thePathDB = request("thePathDB"
boolIs97 = request("boolIs97"
if thePathDB <> "" Then
thePathDB = server.mappath(thePathDB)
response.write(Squish(thePathDB,boolIs97))
End if
%>
</P></BODY></HTML>
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.