利用CompactRepair方法进行MDB文件备份-叶海峰
Access软件网QQ交流学习群(群号码198465573),欢迎您的加入!
首页 >技术文章> Access数据库-模块/函数/VBA


利用CompactRepair方法进行MDB文件备份

发表时间:2011/11/8 10:02:14 评论(0) 浏览(7802)  评论 | 加入收藏 | 复制
   
摘 要:利用CompactRepair方法进行MDB文件备份
正 文:
以下为CompactRepair方法的VBA帮助里面的示例


Function RepairDatabase(strSource As String, _
        strDestination As String) As Boolean
        ' Input values: the paths and file names of
        ' the source and destination files.
    ' Trap for errors.
    On Error GoTo error_handler
    ' Compact and repair the database. Use the return value of
    ' the CompactRepair method to determine if the file was
    ' successfully compacted.
    RepairDatabase = _
        Application.CompactRepair( _
        LogFile:=True, _
        SourceFile:=strSource, _
        DestinationFile:=strDestination)
    ' Reset the error trap and exit the function.
    On Error GoTo 0
    Exit Function
' Return False if an error occurs.
error_handler:
    RepairDatabase = False
End Function
 
很容易就能明白,CompactRepair方法本来是用来修复压缩指定的MDB文件,但原始文件被压缩后会生成一个新的MDB文件,那就可以利用这个功能,进行备份了,而且备份文件和filecopy方法或者API文件复制的方法相比,是经过压缩修复的.缺点就是源文件必须是不被打开状态.
以下为调用方法,如果只需要备份的话,就可以将删除文件,重命名的代码给注释掉
 
Public Function AutoCompactCurrentProject()
    Dim fs, f, s, filespec
    Dim strProjectPath As String, strProjectName As String
    Call RepairDatabase("c:\上标与下标.mdb", "c:\1.mdb")
    Set fs = CreateObject("Scripting.FileSystemObject")
    f = fs.deletefile("c:\上标与下标.mdb", False) '删除原始文件
  Name "c:\1.mdb" As "c:\上标与下标.mdb" '将压缩修复后的文件改名
End Function

Access软件网交流QQ群(群号:198465573)
 
 相关文章
如何删除SQL Server 2005 Compact Editi...  【UMVSoft整理  2008/6/10】
SQL Server 2005 Compact Edition服务...  【UMVSoft整理  2008/8/1】
SQL Server 2005 Compact Edition开发...  【UMVSoft整理  2008/8/2】
SQL异机备份\SQL Server2000异机备份  【转载(风行)  2012/8/25】
SQL server 2005数据库的备份与还原  【缪炜  2012/9/20】
常见问答
技术分类
相关资源
文章搜索
关于作者

叶海峰

文章分类

文章存档

友情链接