compact code in Access 2007

JJJT

Registered User.
Local time
Today, 13:10
Joined
Apr 3, 2009
Messages
10
There is some code in Access 2007 Compact ..???
 
if you mean this​


Public Sub CompactData()
'---------------------------------------------------------------------------------------
' Procedure : CompactData
' DateTime : 8/1/2006 14:57
' Author : Bob Larson
' Purpose : compacts the database
'---------------------------------------------------------------------------------------
'
' you must make sure all objects are closed before trying to compact

Dim frm As Form
Dim rpt As Report
For Each frm In Forms
DoCmd.Close acForm, frm.Name, acSaveNo
Next frm
For Each rpt in Reports
DoCmd.Close acReport, rpt.Name, acSaveNo
Next rpt
SendKeys "%(FMC)", False
End Sub

not working​

 
if you mean this​


Public Sub CompactData()
'---------------------------------------------------------------------------------------
' Procedure : CompactData
' DateTime : 8/1/2006 14:57
' Author : Bob Larson
' Purpose : compacts the database
'---------------------------------------------------------------------------------------
'
' you must make sure all objects are closed before trying to compact

Dim frm As Form
Dim rpt As Report
For Each frm In Forms
DoCmd.Close acForm, frm.Name, acSaveNo
Next frm
For Each rpt in Reports
DoCmd.Close acReport, rpt.Name, acSaveNo
Next rpt
SendKeys "%(FMC)", False
End Sub

not working​



When you say - "not working" what does "not working" mean? It generates an error, it goes through the motions but does nothing, etc.
 

Unfortunately I can't do that while at work (Not only is that link blocked by work, but I don't have 2007 at work either).

Here's another method you can try:

Code:
Dim strDbNameOld As String
Dim strDBNameNew As String

strDbNameOld = "YourPathAndNameToTheFileYouWantToCompact"

        DBEngine.CompactDatabase strDBNameOld, strDBNameNew
        Kill strDBNameOld
        Name strDBNameNew As strDBNameOld
 

Users who are viewing this thread

Back
Top Bottom