怎么在vb6.0中编写代码实现Access2003数据备份与数据恢复
1个回答
展开全部
添加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
'备份数据库到指定目录
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
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |