wildcanada1
Programmer
Hi all
For awhile now I've been looking over the ways to compact a database in Access '97 and I finally found a solution that I like.
-- Create a new database called "startup.mdb".
-- Create a form with one button with the following code behind it:
Private Sub cmdCOMPACT_Click()
CompactDatabaseX
End Sub
-- And then create the CompactDatabaseX subroutine:
Function CompactDatabaseX()
Dim stappname As String
'Delete the last temporary compacted database
If Dir("compacted.mdb" <> "" Then
Kill "compacted.mdb"
End If
'Compact your database.
DBEngine.CompactDatabase "original.mdb", "compacted.mdb"
'Rename your database back to "original.mdb"
FileCopy "compacted.mdb", "orginal.mdb"
'Launch your newly compacted database
stappname = "MSAccess.exe " & "original.mdb"
Call Shell(stappname, 1)
'Close the StartUp Database
DoCmd.Quit
End Function
I hope this helps.
This is my first post so if anyone has any comments let me know.
Mike
For awhile now I've been looking over the ways to compact a database in Access '97 and I finally found a solution that I like.
-- Create a new database called "startup.mdb".
-- Create a form with one button with the following code behind it:
Private Sub cmdCOMPACT_Click()
CompactDatabaseX
End Sub
-- And then create the CompactDatabaseX subroutine:
Function CompactDatabaseX()
Dim stappname As String
'Delete the last temporary compacted database
If Dir("compacted.mdb" <> "" Then
Kill "compacted.mdb"
End If
'Compact your database.
DBEngine.CompactDatabase "original.mdb", "compacted.mdb"
'Rename your database back to "original.mdb"
FileCopy "compacted.mdb", "orginal.mdb"
'Launch your newly compacted database
stappname = "MSAccess.exe " & "original.mdb"
Call Shell(stappname, 1)
'Close the StartUp Database
DoCmd.Quit
End Function
I hope this helps.
This is my first post so if anyone has any comments let me know.
Mike