MDB file 自動壓縮

2007-09-27 8:16 am
每次Import file 入Access MDB 後, 就算用Delete Query 將Table 內的Data 清除, MDB 的file size 都不會自動縮減, 要用工具列裡面的【工具】→【資料庫公用程式】→【壓縮及修復資料庫】才可以讓容量縮小。
請問Marco 或者VBA 有沒有相關的自動功能, 可以在“Event Procdure”執行?

回答 (2)

2007-09-27 12:14 pm
✔ 最佳答案
Method 1: Probably it is what you are looking for

Open Access database, Tools -> Options -> General tab
Check the Compact on Close option

Method 2: VBA

A database cannot compact itself while it is open. You need another access database or program to compact your live database.

1. Create a new access database.
2. Create a new module, put the follow codes in the module

Function CompactDatabase()
Dim ac As New Access.Application

' use either one of the two methods below, do not use both
ac.CompactRepair "c:\temp\Live.mdb", "c:\temp\Temp.mdb" 'Compact the life database to a temp database
' or this
ac.DBEngine.CompactDatabase "c:\temp\Live.mdb", "c:\temp\Temp.mdb"

FileCopy "c:\temp\Temp.mdb", "c:\temp\Live.mdb" 'Make a copy of the compacted database
Kill "c:\temp\Temp.mdb" 'Delete the temp database
MsgBox "Live.mdb has been compacted successfully"
End Function

3. Create a new Macro
Macro Name: CompactDatabase
Action: RunCode
Function Name: CompactDatabase()
Save the Macro

Running this Macro will compact your live database. You can also use the CompactDatabase macro in any Event Procedure.
2007-09-27 9:00 am
要用vb 做,
再用scheduler run 佢定時做
因為mdb 佢或sql 唔會自己做shinking


收錄日期: 2021-04-13 13:38:23
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20070927000051KK00121

檢視 Wayback Machine 備份