Private Sub m_t_Backup_Click()
On Error GoTo hError
Dim sPath As String
sPath = App.Path & "\Backup"
If Dir(sPath, vbDirectory) = "" Then _
Call modErrors.fun_CreateDir(sPath)
sPath = sPath & "\Market" & Format$(Date, "YYYYMMDD") & ".mdb"
If Dir(sPath) <> "" Then Kill sPath
DataEnv.dbCn.Close
FileCopy App.Path & "\Data\Market.mdb", sPath
MsgBox "数据备份成功!", vbInformation, "提示"
DataEnv.dbCn.Open
Set DataEnv.Commands("dbCm").ActiveConnection = DataEnv.dbCn
Exit Sub
hError:
Call sub_DoErrors("frmMain->m_t_Backup_Click", Err.Number, Err.Description)
MsgBox "数据备份失败!", vbCritical, "错误"
End Sub
On Error GoTo hError
Dim sPath As String
sPath = App.Path & "\Backup"
If Dir(sPath, vbDirectory) = "" Then _
Call modErrors.fun_CreateDir(sPath)
sPath = sPath & "\Market" & Format$(Date, "YYYYMMDD") & ".mdb"
If Dir(sPath) <> "" Then Kill sPath
DataEnv.dbCn.Close
FileCopy App.Path & "\Data\Market.mdb", sPath
MsgBox "数据备份成功!", vbInformation, "提示"
DataEnv.dbCn.Open
Set DataEnv.Commands("dbCm").ActiveConnection = DataEnv.dbCn
Exit Sub
hError:
Call sub_DoErrors("frmMain->m_t_Backup_Click", Err.Number, Err.Description)
MsgBox "数据备份失败!", vbCritical, "错误"
End Sub
Dim st As String
Dim bksql As String
Dim bkfolder As String
Dim serial As String
Dim xold As String
Dim xnew As String
Dim bkfso
If MsgBox("确认对当前数据库进行备份?", vbYesNo, "提示信息") = vbNo Then
Exit Sub
End If
st = MDIFm.Lb_gd.Caption
MDIFm.Lb_gd.Caption = "开始数据库备份。"
Set bkfso = CreateObject("Scripting.FileSystemObject")
If (bkfso.FileExists("d:\data_backup\readme.txt")) Then
xnew = "d:\data_backup\zydb.bak"
xold = "d:\data_backup\old\zydb.bak"
If bkfso.FileExists(xnew) Then
If bkfso.FileExists(xold) Then bkfso.deletefile (xold)
Dim ff
Set ff = bkfso.GetFile(xnew)
Sleep 1000
ff.Move xold
End If
bksql = " USE master" + _
" EXEC sp_addumpdevice 'disk', 'backdb" + serial + "', '" + xnew + "'" + _
" BACKUP DATABASE " + bakdb + " TO backdb" + serial + " exec sp_dropdevice 'backdb" + serial + "'"
Call cnn_base.Execute (bksql)
MDIFm.Lb_gd.Caption = "数据库备份备份完毕。"
Sleep 1000
MsgBox "数据库备份完毕。新备份文件完整路径为: d:\data_backup\zydb.bak", vbOKOnly, "提示"
Else
Call Create_db_back_Folder
bksql = " USE master" + _
" EXEC sp_addumpdevice 'disk', 'backdb1', 'd:\data_backup\zydb.bak'" + _
" BACKUP DATABASE " + bakdb + " TO backdb1 exec sp_dropdevice 'backdb1'"
cnn_base.Execute bksql
Sleep 1000
MDIFm.Lb_gd.Caption = "数据库备份备份完毕。"
MsgBox "数据库备份完毕。备份文件完整路径为: d:\data_backup\zydb.bak", vbOKOnly, "提示"
End If
MDIFm.Lb_gd.Caption = st
Set bkfso = Nothing
cnn_base.Execute ("use zyzy")
End SubPrivate Sub Create_db_back_Folder()
Dim fs
Dim fldr
Dim aa
Set fs = CreateObject("Scripting.FileSystemObject")
Set fldr = fs.CreateFolder("d:\data_backup")
Set fldr = fs.CreateFolder("d:\data_backup\old")
Sleep 1000
Set aa = fs.CreateTextFile("d:\data_backup\readme.txt", True)
aa.WriteLine ("data_backup文件夹,用于XXX管理系统的数据库备份,请不要随意删除或移动。")
aa.Close
Set fs = Nothing
End Sub
用其NewMDB过程建一个新库,参照其frmImpExpcmd的Export_Click()导出表
能给点注释吗?有点看不懂