我有一些VB代码看不懂,请高手指教!!!

2024-12-21 23:19:00
推荐回答(1个)
回答1:

On Error GoTo Err
SaveSetting App.Path, "Settings", "DatabasePath", Trim(Text1.Text)
mFso.CopyFile App.Path + "\database.mdb", Trim(Text1.Text) & "\" & DateChange(Date) & ".mdb", True '选择路径备份数据库!MsgBox "数据库备份成功!", , "提示"
Unload Me '关闭窗口。
Exit Sub
Err:
MsgBox Err.Description '返回在所指定的记录源中能找到的所有字段.
End Sub
2.Private Sub Command1_Click()
On Error GoTo Err
CommonDialog1.ShowOpen
Text1.Text = CommonDialog1.FileName

Err:

End Sub
3.Private Sub Command2_Click()
On Error GoTo Err
Dim ss As Integer
If Trim(Text1.Text) = "" Then
MsgBox "请选择数据库!", , "提示"
Exit Sub

End If
ss = MsgBox("真的恢复数据库,原数据将被重写吗?", vbCritical + vbOKCancel, "系统提示")
If ss = 1 Then
CN.Close
Set CN = Nothing
' Kill App.Path + "\database.mdb"
mFso.CopyFile Text1.Text, App.Path + "\database.mdb", True
If CN.State Then CN.Close
CN.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\database.mdb;Persist Security Info=False"
CN.Open
MsgBox "恢复成功!", , "提示"
Unload Me
End If
Exit Sub
Err:
MsgBox Err.Description
End
End Sub

这个下面的就是反过来写而已!~这个备份太过麻烦,我给你段代码。

先在工程里面加入commdilog 控件

On Error GoTo err
dialog.FileName = ""
dialog.Filter = "MDB files(*.mdb).*.mdb"
dialog.ShowSave

If dialog.FileName <> "" Then
FileCopy App.Path & "\tel.mdb", dialog.FileName
MsgBox "备份数据完成", vbOKOnly, ""
End If

Exit Sub
err:
MsgBox "对不起,备份出错,请关闭所有的子窗口,重新备份.", vbOKOnly, "通知"

On Error GoTo err
dialog.FileName = ""
dialog.Filter = "MDB files(*.mdb).*.mdb"
dialog.ShowSave

If dialog.FileName <> "" Then
FileCopy dialog.FileName, App.Path & "\tel.mdb"
MsgBox "恢复数据完成", vbOKOnly, ""
End If