看个例子
Private Sub Backup_Click()
Dim mfile As String, mfile2 As String
On Error Resume Next
CommonDialog1.InitDir = App.Path
CommonDialog1.Filter = "Access文件(*.mdb)|*.mdb"
CommonDialog1.ShowSave
mfile = App.Path & "\db2.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 Backup_Click()
Dim mfile As String, mfile2 As String
On Error Resume Next
CommonDialog1.InitDir = App.Path
CommonDialog1.Filter = "Access文件(*.mdb)|*.mdb"
CommonDialog1.ShowSave
mfile = App.Path & "\db2.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
要先引用 microsoft activex data objects 8.0 library
On Error Resume Next
实际上8楼的代码就可以,lz的代码只有关闭,没见备份