We help IT Professionals succeed at work.

Compact Access

sonic2000
sonic2000 asked
on
Anyway to compact an access database?
Comment
Watch Question

CERTIFIED EXPERT
Commented:
Try this

<%
strDBFile = "e:\_code samples\db\northwind45.mdb" 'change this
strCompactedDBFile = "e:\_code samples\db\northwind_dao2.mdb" 'change this

Set objDAO_DBEngine = Server.CreateObject("DAO.DBEngine.35")
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

If objFSO.FileExists(strCompactedDBFile) Then
   objFSO.DeleteFile (strCompactedDBFile)
End If

objDAO_DBEngine.CompactDatabase strDBFile, strCompactedDBFile

objFSO.CopyFile strCompactedDBFile, strDBFile

'objFSO.DeleteFile (strCompactedDBFile) 'delete the copy
'- we want to see the copy and the file size, for now

Set objFSO = Nothing
Set objDAO_DBEngine = Nothing
%>

Above works fine with Access 97
For Access2k use ProgID DAO.DBEngine.36


hongjun

Explore More ContentExplore courses, solutions, and other research materials related to this topic.