Access VBA 問題, COMPACT Database

2007-04-19 12:01 am
Private Sub button_Click()
DoCmd.RunCommand acCmdCompactDatabase
End Sub
我用上述句式來Run,不過出現以下錯誤message。
「您無法在巨集或 Visual Basic 程式碼執行時壓縮資料庫。
但是可以使用[工具]功能表的[資料庫公用程式],有個〔壓縮資料庫〕的功能代替之。」
請問我應如何運用VBA或巨集,才能建立用來壓縮資料庫的按紐,謝謝!

回答 (1)

2007-04-21 2:25 pm
✔ 最佳答案
I don't know why Microsoft gives us acCmdCompactDatabase. You can NEVER compact a database while it is open. In other words, a form can never compact the database it is in.

You can compact another database using these codes.

Dim obj As New Access.Application
obj.CompactRepair "c:\source.mdb", "c:\destination.mdb"
' or this
obj.DBEngine.CompactDatabase "c:\source.mdb", "c:\destination.mdb"


收錄日期: 2021-04-16 16:08:17
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20070418000051KK01945

檢視 Wayback Machine 備份