private Sub mnu_sj_bf_Click()
Dim i As String
On Error Resume Next
With cdlog1
.DialogTitle = "数据备份"
.InitDir = App.Path
.filename = "backup.mdb"
.Filter = "(数据库)*.mdb|*.mdb"
.CancelError = True
.ShowSave
i = .filename
End With
If Right$(App.Path, 1) <> "\" Then spath = App.Path & "\"
ssource = spath & "mdb\che.lbl"
sdest = i
If Err.Number <> cdlCancel Then
On Error GoTo sjbf_error
If Dir$(i) <> "" Then
s = MsgBox("文件已存在,确认替换它!", vbYesNo + vbQuestion)
If s = 6 Then
'FileCopy ssource, sdest
Kill sdest
DBEngine.CompactDatabase ssource, sdest
MsgBox "数据备份成功!", vbInformation
Else
mnu_sj_bf_Click
End If
Else
'FileCopy ssource, sdest
DBEngine.CompactDatabase ssource, sdest
MsgBox "数据备份成功!", vbInformation
End If
End If
Exit Sub
sjbf_error:
If Err = 70 Then
MsgBox "数据库正在使用,请关闭所有数据窗口,从新开始备份", vbExclamation
Else
MsgBox Err.Description, vbExclamation
End If
End Sub
Private Sub mnu_sj_hf_Click()
Dim i As String
On Error Resume Next
With cdlog1
.DialogTitle = "数据恢复"
.InitDir = App.Path
.Filter = "(数据库)*.mdb|*.mdb"
.CancelError = True
.Flags = cdlOFNHideReadOnly Or cdlOFNFileMustExist
.ShowOpen
i = .filename
End With
ssource = i
If Right$(App.Path, 1) <> "\" Then spath = App.Path & "\"
sdest = spath & "mdb\che.lbl"
temp1 = fullpath("mdb\backup.mdb")
' If Dir(temp1) = True Then Kill
If Err.Number <> cdlCancel Then
On Error GoTo sjh_error
s = MsgBox("系统数据将全部丢失,确认要从数据文件" & i & "中恢复系统数据吗?", vbYesNo + vbQuestion)
If s = 6 Then
FileCopy sdest, temp1
FileCopy ssource, sdest
MsgBox "数据恢复成功!", vbInformation
End If
End If
Exit Sub
sjh_error:
If Err = 70 Then
MsgBox "数据库正在使用,请关闭所有数据窗口,从新开始恢复", vbExclamation
Else
MsgBox Err.Description, vbExclamation
End If
End Sub