在ACCESS中自動壓縮當(dāng)前數(shù)據(jù)庫

字號:


    ACCESS可在菜單上選擇[壓縮]來壓縮當(dāng)前正打開的數(shù)據(jù)庫,如是我們就可以通過程序臨時添加一個工具條按鈕,然后使用SendKeys來模擬鍵盤操作,實現(xiàn)壓縮當(dāng)前數(shù)據(jù)庫,壓縮后它會重新打開。函數(shù)如下:
    FunctionCompact()
    '添加一個工具條
    WithCommandBars.Add(,msoBarFloating,,True)
    '在工具條上添加一個按鈕,這個按鈕是從系統(tǒng)菜單的[工具]中[壓縮]產(chǎn)生的
    .Controls.AddmsoControlButton,CommandBars("Tools").Controls(7).CommandBar.Controls(2).Id
    .Visible=True
    '將焦點移到該按鈕上
    .Controls(1).SetFocus
    '模擬擊鍵
    SendKeys"{ENTER}"
    EndWith
    EndFunction