Access “Compact and Repair” programmatically

前端 未结 7 652
逝去的感伤
逝去的感伤 2020-12-03 22:28

Is it possible to \"compact and repair\" an Access database programmatically somehow (using ADOX, using OleDbConnection etc.)?

7条回答
  •  旧巷少年郎
    2020-12-03 22:35

    Add ref to: Microsoft ActiveX Data Objects 2.x Library Microsoft Jet and Replication Objects 2.x Library

    sDB = "c:\DB\myDb.mdb"
    sDBtmp = "c:\DB\tempMyDb.mdb"
    sPASSWORD = "password"
    
    Dim oApp As Access.Application
    Set oApp = New Access.Application
    Call oApp.DBEngine.CompactDatabase(sDB, sDBtmp, dbLangGeneral, , ";pwd=" & sPASSWORD)
    
    'wait for the app to finish
            DoEvents
    'remove the uncompressed original
            Kill sDB
    'rename the compressed file to the original to restore for other functions
            Name sDBtmp As sDB
    

提交回复
热议问题