适用 ACCESS2000及当前版本
首先在公共模块添加如下函数:
以下为援用的内容:
Public Function AutoCompactCurrentProject() Dim fs, f, s, filespec Dim strProjectPath As String, strProjectName As String strProjectPath = Application.CurrentProject.Path strProjectName = Application.CurrentProject.Name filespec = strProjectPath & "\" & strProjectName Set fs = CreateObject("Scripting.FileSystemObject") Set f = fs.GetFile(filespec) s = CLng(f.Size / 1000000) ‘转换文件大小为MB If s > 20 Then ‘修正此处的20M为你本人需求的值 Application.SetOption ("Auto Compact"), 1 ‘紧缩程序 Else Application.SetOption ("Auto Compact"), 0 ‘不紧缩程序 End If End Function
|
在任何退出的程序前调用这个函数,例如在Docmd.Quit前调用:AutoCompactCurrentProject