Link to home
Start Free TrialLog in
Avatar of speedbit
speedbit

asked on

How automatically doing Compact and Repair Database?

Hej!!

i noticed that MS Access Database size always become larger until i do compact and repair database! .. why its always doing like this.. whatever the reason i think its bad feature.. why MS Access not doing compact and repair automatically? .. is there a way for doing this automatically.. the problem that i'm using access database from delphi application.. how to do this automatically from external environment not from ms access .. !?

I'm using MS Access 2003
Avatar of tbsgadi
tbsgadi
Flag of Israel image

Hi speedbit,

Everything you want to know about bloating mdbs
http://www.granite.ab.ca/access/bloatfe.htm


Good Luck!

Gary
Avatar of Wayne Taylor (webtubbs)
Hello speedbit,

In VB, you'd use code like this to compact and repair an access database....

     Public Sub CompactAccessDataBase(dbPath As String, NewPath As String)
         Dim acc As Object
         Set acc = CreateObject("Access.Application")
         acc.CompactRepair dbPath, NewPath
         Set acc = Nothing
     End Sub
     
     Sub test()
         CompactAccessDataBase "C:\YourDatabase.mdb", "C:\YourDatabase_NEW.mdb"
     End Sub

Regards,

Wayne
Avatar of speedbit
speedbit

ASKER

thank you, but i still need a code or method to automatically repair the database file from outside ms access
speedbit,

You can use that code I posted. By modifying it slightly, you can create a VB script file, and set it to run every so ofter via the Windows Task Scheduler.

Open Notepad, and paste in this code....

     dim OldFile, NewFile, Acc,FSO, comp
     OldFile = "C:\db1.mdb"
     NewFile = "C:\db2.mdb"
     Set acc = CreateObject("Access.Application")
     Set FSO = CreateObject("Scripting.FileSystemObject")
     comp = acc.CompactRepair(OldFile, NewFile)
     FSO.DeleteFile OldFile
     FSO.MoveFile NewFile, OldFile
     Set acc = Nothing
     Set FSO  = Nothing

Save the file as CompactDB.vbs, where ever you like.

Then add a new task to Scheduled Tasks, pointing it to the vbs file you created.

Wayne
thank you but i need a delphi code
ASKER CERTIFIED SOLUTION
Avatar of 3ezz
3ezz

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial