Results 1 to 5 of 5

Thread: Compact & repair database

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2000
    Location
    Chicago
    Posts
    97

    Compact & repair Access 2000 database

    Hi,
    I know that we can compact and repair database with Tools>database utilities>compact& repair database option,but can anyone tell me as is it possible to do this with the code.Iam using Access2000
    Any help will be highly appreciated.

    Regards
    Anil

  2. #2
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    617

    ...

    try this...

    Private Sub Command1_Click()
    ' this line will compact the "c:\myDir\db1.mdb" database to "c:\myDir\db2.mdb".
    ' after this line had been called you will have the original
    ' uncompacted database in "c:\myDir\db1.mdb"
    ' and the new compacted database in "c:\myDir\db2.mdb".
    DBEngine.CompactDatabase "c:\myDir\db1.mdb", "c:\myDir\db2.mdb"
    End Sub


    and let us know

  3. #3
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    I tried writing code once using Access VBA to issue the Compact and Repair command after a function that deleted records from a table, and I got an error message telling me the c&r command cannot be executed via code...

    Josh

  4. #4
    Fanatic Member
    Join Date
    Oct 2000
    Location
    London
    Posts
    1,008
    Perfectly possible but remember that Compact and Repair operations need exclusive access to the database so have to be done from a separate piece of code. Running it from VB via automation would be fine.

    Lafor's code would work but it could not be run from c:\myDir\db1.mdb itself.

    Cheers,

    P.
    Not nearly so tired now...

    Haven't been around much so be gentle...

  5. #5
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    Yeah, I was using this in Access VBA. It is from Access.Application.

    Code:
    RunCommand acCmdCompactDatabase
    So in other words, you can compact a DB from Access VBA, only VB.

    Josh

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width