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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compact database automatically

Status
Not open for further replies.

ngagne

Technical User
Joined
Sep 14, 2001
Messages
323
Location
US
Access 2002

I know you can compact on close, but I want to "schedule" a compact every night. Is this possible? I don't mind using code if that's what I have to do. Nate Gagne
nathan.gagne@verizon.net
AKA Nick Burns - Your Company's Computer Guy
"Would you like me to save your game of Minesweeper first?"

Like my post? Let me know it was helpful!
 
It is possible. Use the CompactDatabase method of the DBEngine Object. This method also translates from one version to another.

Here's a snippit stolen from:

[tt]
Option Explicit

Private Sub Command1_Click()

Const dbPath = "C:\Program Files\ACCESS20\SAMPAPPS\NWIND"

Dim db As Database
Set db = DBEngine(0).OpenDatabase(dbPath)
Debug.Print dbPath & " Version:", db.Version
db.Close

DBEngine.CompactDatabase dbPath & ".mdb", _
dbPath & "30.mdb", _
, _
dbVersion30

Set db = DBEngine(0).OpenDatabase(dbPath & "30")
Debug.Print dbPath & "30 Version:", db.Version
db.Close

Kill dbPath & "30.mdb"

End Sub
[/tt]

Wil Mead
wmead@optonline.net
 
Awww, crap. I posted this in the wrong forum! Thanks for the reply Wil.

Nate Gagne
nathan.gagne@verizon.net
AKA Nick Burns - Your Company's Computer Guy
"Would you like me to save your game of Minesweeper first?"

Like my post? Let me know it was helpful!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top