使用select * into backuptable in "c:\backup\backup.mdb" from tablename where id=...
Option ExplicitPrivate Sub cmdCancel_Click() Unload Me End SubPrivate Sub cmdSave_Click() Select Case SSTab1.Tab Case 0 If BackupData(txtPath(0).Text) = True Then MsgBox "备份文件成功!", vbOKOnly, App.Title Unload Me Else MsgBox "背份文件失败!请检查路径和当前的数据连接!", vbOKOnly, App.Title Exit Sub End If Case 1 If RestoreData(txtPath(1).Text) = True Then MsgBox "恢复文件成功!", vbOKOnly, App.Title Unload Me Else MsgBox "背份文件失败!请检查路径和当前的数据连接!", vbOKOnly, App.Title Exit Sub End If End Select End SubPrivate Sub cmdSelect_Click(Index As Integer)
ChDir (App.Path) cdlBrowser.Filter = "备份文件(*.ZYB)|*.ZYB" cdlBrowser.CancelError = True On Error GoTo errhandle: Select Case Index Case 0 cdlBrowser.DialogTitle = "保存文件到" cdlBrowser.FileName = "数据备份" & Format(Date, "yyyy-mm-dd")
cdlBrowser.ShowSave Case 1 cdlBrowser.FileName = "" cdlBrowser.DialogTitle = "选择文件" cdlBrowser.ShowOpen End Select If Err.Number <> 0 Then Exit Sub Else If SSTab1.Tab = 0 Then txtPath(0).Text = cdlBrowser.FileName ElseIf SSTab1.Tab = 1 Then txtPath(1).Text = cdlBrowser.FileName End If End If errhandle: Exit Sub End SubPrivate Function BackupData(z As String) As Boolean Dim i As Long i = CopyFile(MyAppPath & "Data\DB.MDB", z, 0) If i <> 0 Then BackupData = True Else BackupData = False End If End FunctionPrivate Function RestoreData(s As String) As Boolean Dim i As Long i = CopyFile(s, MyAppPath & "Data\Temp.MDB", 0) If i <> 0 Then i = DeleteFile(MyAppPath & "Data\Db.MDB") If i <> 0 Then Name MyAppPath & "Data\Temp.MDB" As MyAppPath & "data\Db.mdb" RestoreData = True End If Else RestoreData = False End If End FunctionPrivate Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = vbKeyReturn Then SendKeys "{TAB}" If KeyCode = vbKeyEscape Then Unload MeEnd SubPrivate Sub Form_Load() Set Me.Icon = frmParent.Icon End Sub
Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" (ByVal lpExistingFileName As String, _ ByVal lpNewFileName As String, ByVal bFailIfExists As Long) As Long Declare Function DeleteFile Lib "kernel32" Alias "DeleteFileA" (ByVal lpFileName As String) As Long
Unload Me
End SubPrivate Sub cmdSave_Click()
Select Case SSTab1.Tab
Case 0
If BackupData(txtPath(0).Text) = True Then
MsgBox "备份文件成功!", vbOKOnly, App.Title
Unload Me
Else
MsgBox "背份文件失败!请检查路径和当前的数据连接!", vbOKOnly, App.Title
Exit Sub
End If
Case 1
If RestoreData(txtPath(1).Text) = True Then
MsgBox "恢复文件成功!", vbOKOnly, App.Title
Unload Me
Else
MsgBox "背份文件失败!请检查路径和当前的数据连接!", vbOKOnly, App.Title
Exit Sub
End If
End Select
End SubPrivate Sub cmdSelect_Click(Index As Integer)
ChDir (App.Path)
cdlBrowser.Filter = "备份文件(*.ZYB)|*.ZYB"
cdlBrowser.CancelError = True
On Error GoTo errhandle:
Select Case Index
Case 0
cdlBrowser.DialogTitle = "保存文件到"
cdlBrowser.FileName = "数据备份" & Format(Date, "yyyy-mm-dd")
cdlBrowser.ShowSave
Case 1
cdlBrowser.FileName = ""
cdlBrowser.DialogTitle = "选择文件"
cdlBrowser.ShowOpen
End Select
If Err.Number <> 0 Then
Exit Sub
Else
If SSTab1.Tab = 0 Then
txtPath(0).Text = cdlBrowser.FileName
ElseIf SSTab1.Tab = 1 Then
txtPath(1).Text = cdlBrowser.FileName
End If
End If
errhandle:
Exit Sub
End SubPrivate Function BackupData(z As String) As Boolean
Dim i As Long
i = CopyFile(MyAppPath & "Data\DB.MDB", z, 0)
If i <> 0 Then
BackupData = True
Else
BackupData = False
End If
End FunctionPrivate Function RestoreData(s As String) As Boolean
Dim i As Long
i = CopyFile(s, MyAppPath & "Data\Temp.MDB", 0)
If i <> 0 Then
i = DeleteFile(MyAppPath & "Data\Db.MDB")
If i <> 0 Then
Name MyAppPath & "Data\Temp.MDB" As MyAppPath & "data\Db.mdb"
RestoreData = True
End If
Else
RestoreData = False
End If
End FunctionPrivate Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then SendKeys "{TAB}"
If KeyCode = vbKeyEscape Then Unload MeEnd SubPrivate Sub Form_Load()
Set Me.Icon = frmParent.Icon
End Sub
Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" (ByVal lpExistingFileName As String, _
ByVal lpNewFileName As String, ByVal bFailIfExists As Long) As Long
Declare Function DeleteFile Lib "kernel32" Alias "DeleteFileA" (ByVal lpFileName As String) As Long
FileCopy是什么?