在VB中利用CommonDialog控件备份数据

来源:百度知道 编辑:UC知道 时间:2024/05/11 04:05:21
将程序Data文件夹下的data.mdb文件备份,并且自动命名为"当前日期.bak"

源目录在data下,目标目录和文件名确定,为什么还要用commondialog?

Private Sub mnubackup_Click()
Dim ss As Long
With dlgCommonDialog
Dim sFile, dfile As String
.DialogTitle = "另存为"
.CancelError = False
.Filter = "题库文件(*.mdb)|*.mdb|所有文件(*.*)|*.*"
.InitDir = App.Path + fpath + "data"
.filename = ""
.ShowSave
If Len(.filename) = 0 Then
Exit Sub
End If
sFile = .filename
dfile = App.Path + fpath + "data\kaoti.mdb"
End With
ss = CopyFile(dfile, sFile, 2)
If ss <> 0 Then
MsgBox "数据库备份失败,请重试!", vbExclamation, "错误"
Else
MsgBox "数据库备份成功!", vbInformation, "成功"
End If
End Sub

没必要用CommonDialog吧?
Dim Path As String
Path = App.Path & IIf(Len(App.Path) = 3, "", "\")
FileCopy Path & "Data\Data.md