VB icon

Compact Access DB using ASP

Email
Submitted on: 1/6/2015 3:23:00 AM
By: John Tropeano (from psc cd)  
Level: Intermediate
User Rating: By 3 Users
Compatibility: ASP (Active Server Pages), HTML, VbScript (browser/client side)
Views: 978
 
     This code snippet will compact your Access DB online. You can do this via a web browser!
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: Compact Access DB using ASP
' Description:This code snippet will compact your Access DB online. You can do this via a web browser!
' By: John Tropeano (from psc cd)
'
' Inputs:Path to database
'**************************************

<%
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>


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.