利用CompactRepair方法进行MDB文件备份
时 间:2011-11-08 10:02:14
作 者:叶海峰 ID:31 城市:广州
摘 要:利用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
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群 (群号:54525238) Access源码网店
常见问答:
技术分类:
源码示例
- 【源码QQ群号19834647...(12.17)
- 统计当月之前(不含当月)的记录...(03.11)
- 【Access Inputbo...(03.03)
- 按回车键后光标移动到下一条记录...(02.12)
- 【Access Dsum示例】...(02.07)
- Access对子窗体的数据进行...(02.05)
- 【Access高效办公】上月累...(01.09)
- 【Access高效办公】上月累...(01.06)
- 【Access Inputbo...(12.23)
- 【Access Dsum示例】...(12.16)

学习心得
最新文章
- 32位的Access软件转化为64...(04.12)
- 【Access高效办公】如何让vb...(04.11)
- 仓库管理实战课程(10)-入库功能...(04.08)
- Access快速开发平台--Fun...(04.07)
- 仓库管理实战课程(9)-开发往来单...(04.02)
- 仓库管理实战课程(8)-商品信息功...(04.01)
- 仓库管理实战课程(7)-链接表(03.31)
- 仓库管理实战课程(6)-创建查询(03.29)
- 仓库管理实战课程(5)-字段属性(03.27)
- 设备装配出入库管理系统;基于Acc...(03.24)