當前位置:編程學習大全網 - 編程軟體 - 怎麽在vb6.0中編寫代碼實現Access2003數據備份與數據恢復

怎麽在vb6.0中編寫代碼實現Access2003數據備份與數據恢復

添加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

  • 上一篇:長春達內科技有限公司怎麽樣?
  • 下一篇:什麽是固定循環指令
  • copyright 2024編程學習大全網