Dim SourceFile, DestinationFilePrivate Sub Command1_Click() ' 设置“CancelError”为 True CommonDialog1.CancelError = True On Error GoTo ErrHandler ' 设置标志 CommonDialog1.Flags = cdlOFNHideReadOnly ' 设置过滤器 CommonDialog1.Filter = "Access Files (*.mdb)|*.mdb" ' 显示“另存为”对话框 CommonDialog1.ShowSave' 显示选定文件的名字Exit SubErrHandler: ' 用户按了“取消”按钮 Exit Sub End SubPrivate sub StartCopy() SourceFile = "c:\db1.mdb" ' 指定源文件名。 DestinationFile = commondialog1.filename ' 指定目的文件名。 FileCopy SourceFile, DestinationFile ' 将源文件的内容复制到目的文件中。 exit sub
多谢 yoki(小马哥) ,可是我看到有的是这样写的,我看不大懂,你能帮忙看看吗'********************************************************* Public Sub BackupDatabase() Dim cn As New ADODB.Connection Dim s_path As String Dim s_dataexport As Strings_path = App.path Me.MousePointer = 11 '设置鼠标指针形状 'student1是需要备份的数据库名称 s_dataexport = "backup database a to disk='" + CommonDialog1.FileName + "'" (上面这句是什么意思??我不大懂) cn.Open "[Provider=MSDASQL;] { DSN=a} ; [DATABASE=a;] UID=user; PWD=password" '数据库连接字符串 '这里不需要连接master数据库,即可完成备份 cn.BeginTrans cn.Execute s_dataexport err.Number = 0 If err.Number = 0 Then cn.CommitTrans MsgBox "数据备份成功!", vbInformation, "提示" MsgBox "数据备份文件存放路径:" & CommonDialog1.FileName, vbOKOnly, "提示" Unload Me Else cn.RollbackTrans MsgBox "数据备份失败!请检查数据库是否正在打开!", vbCritical, "提示" End If cn.Close Set cn = Nothing Me.MousePointer = 1 End Sub
yoki(小马哥),你不在吗?? 不会把,帮帮忙把,我怎么看都是不懂啊
s_dataexport = "backup database a to disk='" + CommonDialog1.FileName + "'" 是用CommonDialog1控件打开提示框,需要你自己定位实际备份路径cn.Execute s_dataexport 连接打开上面所得到的路径的数据库
SourceFile = "c:\db1.mdb" ' 指定源文件名。
DestinationFile = commondialog1.filename ' 指定目的文件名。
FileCopy SourceFile, DestinationFile ' 将源文件的内容复制到目的文件中。
' 设置“CancelError”为 True
CommonDialog1.CancelError = True
On Error GoTo ErrHandler
' 设置标志
CommonDialog1.Flags = cdlOFNHideReadOnly
' 设置过滤器
CommonDialog1.Filter = "Access Files (*.mdb)|*.mdb"
' 显示“另存为”对话框
CommonDialog1.ShowSave' 显示选定文件的名字Exit SubErrHandler:
' 用户按了“取消”按钮
Exit Sub
End SubPrivate sub StartCopy()
SourceFile = "c:\db1.mdb" ' 指定源文件名。
DestinationFile = commondialog1.filename ' 指定目的文件名。
FileCopy SourceFile, DestinationFile ' 将源文件的内容复制到目的文件中。
exit sub
Public Sub BackupDatabase()
Dim cn As New ADODB.Connection
Dim s_path As String
Dim s_dataexport As Strings_path = App.path
Me.MousePointer = 11 '设置鼠标指针形状
'student1是需要备份的数据库名称
s_dataexport = "backup database a to disk='" + CommonDialog1.FileName + "'" (上面这句是什么意思??我不大懂)
cn.Open "[Provider=MSDASQL;] { DSN=a} ; [DATABASE=a;] UID=user; PWD=password" '数据库连接字符串
'这里不需要连接master数据库,即可完成备份
cn.BeginTrans
cn.Execute s_dataexport
err.Number = 0
If err.Number = 0 Then
cn.CommitTrans
MsgBox "数据备份成功!", vbInformation, "提示"
MsgBox "数据备份文件存放路径:" & CommonDialog1.FileName, vbOKOnly, "提示"
Unload Me
Else
cn.RollbackTrans
MsgBox "数据备份失败!请检查数据库是否正在打开!", vbCritical, "提示"
End If
cn.Close
Set cn = Nothing
Me.MousePointer = 1
End Sub
不会把,帮帮忙把,我怎么看都是不懂啊
是用CommonDialog1控件打开提示框,需要你自己定位实际备份路径cn.Execute s_dataexport
连接打开上面所得到的路径的数据库