怎么在vb6.0中编写代码实现Access2003数据备份与数据恢复

 我来答
ST磊磊工作室
2012-06-01 · 超过21用户采纳过TA的回答
知道答主
回答量:103
采纳率:0%
帮助的人:62.5万
展开全部
添加CommonDialog控件到窗体上(工程/部件/Microsoft/CommonDialog Control 6.0)

'备份数据库到指定目录
Private Sub Command1_Click()
Dim mfile As String, mfile2 As String
On Error Resume Next
CommonDialog1.Filter = "Access文件|*.mdb"
CommonDialog1.ShowSave
mfile = App.Path & "\db1.mdb " '要备份的文件为当前文件夹下的 db1.mdb
mfile2 = CommonDialog1.FileName '得到目标文件的路径
If Trim(mfile2) = " " Then Exit Sub
If Dir(mfile2) <> " " Then
If MsgBox(Dir(mfile2) & " 文件已经存在,是否替换? ", vbYesNo, "警告 ") = vbNo Then Exit Sub
End If
Dim buff() As Byte, i As Long

i = FileLen(mfile)
ReDim buff(i - 1)

Open mfile For Binary As #1
Get #1, , buff
Close #1

Open mfile2 For Binary As #1
Put #1, , buff
Close #1

MsgBox "备份完毕! "

End Sub

'恢复指定数据库
Private Sub Command2_Click()
Dim mfile As String, mfile2 As String
On Error Resume Next
CommonDialog1.Filter = "Access文件|*.mdb"
CommonDialog1.ShowOpen
mfile = CommonDialog1.FileName '得到别处的Access文件的路径
mfile2 = App.Path & "\db1.mdb " '要覆盖掉当前文件夹下的 db1.mdb

If Trim(mfile) = " " Then Exit Sub

If MsgBox("是否恢复数据库? ", vbYesNo, "警告 ") = vbNo Then Exit Sub

Dim buff() As Byte, i As Long

i = FileLen(mfile)
ReDim buff(i - 1)

Open mfile For Binary As #1
Get #1, , buff
Close #1

Open mfile2 For Binary As #1
Put #1, , buff
Close #1

MsgBox "恢复完毕! "

End Sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式