Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compact Access MDB from VB without DAO or JRO?

Status
Not open for further replies.

JHAMMAR

Programmer
May 6, 1999
1
0
0
US
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,&quot;\&quot;))
Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;)

if fso.FileExists(thePathDB) Then
Set Engine = CreateObject(&quot;JRO.JetEngine&quot;)

if boolIs97 = &quot;True&quot; Then
Engine.CompactDatabase &quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=&quot; & thePathDB, _
&quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=&quot; & strThePathDB & &quot;temp.mdb;&quot; _
& &quot;Jet OLEDB:Engine Type=&quot; & JET_3X
Else
Engine.CompactDatabase &quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=&quot; & thePathDB, _
&quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=&quot; & strThePathDB & &quot;temp.mdb&quot;
End if
fso.CopyFile strThePathDB & &quot;temp.mdb&quot;,thePathDB
fso.DeleteFile(strThePathDB & &quot;temp.mdb&quot;)
Set fso = nothing
Set Engine = nothing
Squish = &quot;Your database, &quot; & thePathDB & &quot;, has been Compacted&quot; & vbCrLf
Else
Squish = &quot;The database name or path has Not been found. Try Again&quot; & vbCrLf
End if

End function
%>
<HTML><HEAD><TITLE>Compact Database</TITLE></HEAD><BODY>

<H2 align=&quot;center&quot;> Compacting Dealer database</H2>
<P align=&quot;center&quot;>
<FORM action=compact.asp>
Enter relative path To the database, including database name.<BR><BR>
<INPUT type=&quot;text&quot; name=&quot;thePathDB&quot; value=&quot;/data/dealers.mdb&quot;>
<BR><BR>
<INPUT type=&quot;checkbox&quot; name=&quot;boolIs97&quot; value=&quot;True&quot;> Check if Access 97 database
<BR><I> (default is Access 2000)</I><BR><BR>
<INPUT type=&quot;submit&quot;>
<FORM>
<BR><BR>
<%
Dim thePathDB,boolIs97
thePathDB = request(&quot;thePathDB&quot;)
boolIs97 = request(&quot;boolIs97&quot;)

if thePathDB <> &quot;&quot; Then
thePathDB = server.mappath(thePathDB)
response.write(Squish(thePathDB,boolIs97))
End if
%>
</P></BODY></HTML>

Regards,

Trope

 
Whoops, misread your initial post. Sorry.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top