'修复压缩数据库
Public Sub RepairDataBase()
    
    Dim TmpData As String
    
    TmpData = App.Path & "\DataBase\tmp.mdb"
        
    If FileExists(TmpData) Then Kill TmpData
    
    DBEngine.CompactDatabase SYSDATABASE, TmpData, , , ";pwd=" & DataBasePWD
    Kill SYSDATABASE
    Name TmpData As SYSDATABASE
    
    If FileExists(TmpData) Then Kill TmpData
    
    DBEngine.CompactDatabase BACKDATABASE, TmpData, , , ";pwd=" & DataBasePWD
    Kill BACKDATABASE
    Name TmpData As BACKDATABASE
End Sub

解决方案 »

  1.   

    用dao,在msdn的例子中有一个visdata 的工程,也就是access97用的里面有压缩和修复的例子的
      

  2.   

    DBEngine.CompactDatabase "源数据库名", "目标数据名"
    可以将源数库压缩并修复到目标数据库
      

  3.   

    如何使用 ADO 來压缩或修复 Microsoft Access 文件?  
    版本:VB6 以前使用 DAO 時,Microsoft 有提供 CompactDatabase Method 來压缩 Microsoft Access 文件,RepairDatabase Method 來修复损坏的 Microsoft Access 文件,。可是自从 ADO 出來之后,好像忘了提供相对的压缩及修复 Microsoft Access 文件的功能。現在 Microsoft 发现了这个问题了,也提供了解決方法,不过有版本上的限制!限制說明如下:ActiveX Data Objects (ADO), version 2.1 
    Microsoft OLE DB Provider for Jet, version 4.0 這是 Microsoft 提出的 ADO 的延伸功能:Microsoft Jet OLE DB Provider and Replication Objects (JRO)这个功能在 JET OLE DB Provider version 4.0 (Msjetoledb40.dll) 及 JRO version 2.1 (Msjro.dll) 中第一次被提出!
    這些必要的 DLL 文件在您安裝了 MDAC 2.1 之后就有了,您可以在以下的网页中下载 MDAC 的最新版本!Universal Data Access Web Site在下载之前先到 VB6 中檢查一下,【控件】【設定引用項目】中的 Microsoft Jet and Replication Objects X.X library 如果已经是 2.1 以上的版本,您就可以不用下载了!在您安裝了 MDAC 2.1 或以上的版本之后,您就可以使用 ADO 來压缩或修复 Microsoft Access 文件,下面的步骤告訴您如何使用 CompactDatabase Method 來压缩 Microsoft Access 文件:1、新建一個新表单,选择功能表中的【控件】【設定引用項目】。
    2、加入 Microsoft Jet and Replication Objects X.X library,其中 ( X.X 大于或等于 2.1 )。
    3、在适当的地方加入以下的程序代码,記得要修改 data source 的內容及目地文件的路径:Dim jro As jro.JetEngine
    Set jro = New jro.JetEngine
    jro.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\\nwind2.mdb", _ '來源文件
    "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\\abbc2.mdb;Jet OLEDB:Engine Type=4" '目的文件在 DAO 3.60 之后,RepairDatabase Method 已经无法使用了,以上的程序代码显示了 ADO CompactDatabase Method 的用法,而它也取代了 DAO 3.5 時的 RepairDatabase method! 
      

  4.   

    我用的是Access2000,我用CompactDatabase报错没找到ISAM
      

  5.   

    If your application cannot connect to the external data source, you can check for the following: Make sure you can access the external table through Windows Explorer or File Manager. If the table is stored on a network share, for example, check that you have sufficient permissions to access that share. 
    Check that the external table is accessible through its native application. For example, if you’re trying to open a Microsoft Excel worksheet, check that you can open the worksheet in Microsoft Excel. 
    Check the code that establishes the connection to the external table carefully to make sure that it follows the guidelines given in “Specifying Connection Information” earlier in this chapter. 
    If you were able to connect to the external table through your application before but you can’t now, check that the table is still in its original location. If the table is linked to your Microsoft Access database and it has been moved, you need to refresh the link before you can access the table.
    See Also   For more information, see “Maintaining Links to External Tables” earlier in this chapter.If you receive the message “Unable to find installable ISAM,” check the source database type specified in your code against those in the table in “Specifying Source Database Types” earlier in this chapter. (Remember that Excel 7.0 isn’t a valid source database type; use Excel 5.0 instead.) 
    If the source database type matches one of the values in the table in “Specifying Source Database Types,” check that the installable ISAM driver resides in the folder specified in the Windows Registry in the \HKEY_LOCAL_MACHINE \SOFTWARE\Microsoft\Jet\3.5\Engines key. 
    If you are supplying arguments to a case-sensitive data source, check that the arguments are of the correct form and case. 
    Make sure the system on which the external data source resides has sufficient disk space. 
    If you are trying to access the table by using Visual Basic code, try to import the table by pointing to Get External Data on the File menu and clicking Import. Check the properties that are set in Design view of the imported table and compare them to the connection string that you are using in your code. 
    Understanding Temporary Space Needs
    Microsoft Access creates temporary indexes on your local computer when you run a query. This occurs even when the data is located in an external data source and in a different file format. These indexes can be as small as a few kilobytes or as large as several megabytes, depending on the data source.You should make sure users of your application have sufficient resources to accommodate these temporary space needs. All users should have a subfolder named Temp in their Windows folder, and enough disk space to store the indexes that Microsoft Access may create.Important If users don’t have the disk space necessary to store temporary indexes, your application may behave unpredictably.
      

  6.   

    lihonggen0(用VB) 到那下再呢
      

  7.   

    你的ADO版本是多少?
    MDAC 2.1就是ADO
    2.1以上就可以了
      

  8.   

    http://www.microsoft.com/data/download.htm2.7下载地址
      

  9.   

    万一压缩出问题:)
    还是这样做吧
    假如真的大了就不建议用Access了