代码我是这么写的
挂在了主窗体上
每次运行时自动备份
Kill App.Path + "\数据库备份\自动备份.dat"
fsouce = App.Path + "\db1.mdb"
FDist = App.Path + "\数据库备份\自动备份.dat"
FileCopy fsouce, FDist
Option Explicit
Dim Rs As ADODB.Recordset Dim ConnStr As String
Private Sub Command1_Click() Set Rs = New ADODB.Recordset ConnStr = "Driver={Microsoft Access Driver (*.mdb)};dbq=" & App.Path & "\db1.mdb" Rs.CursorLocation = adUseClient Rs.Open "Select * from board", ConnStr, adOpenKeyset, adLockOptimistic Set DataGrid1.DataSource = Rs DataGrid1.Refresh End Sub
Private Sub Command2_Click() Dim FDist As String Dim FSource As String
FDist = App.Path & "\自动备份.dat" FSource = App.Path & "\db1.mdb" If Dir(FDist) <> "" Then Kill FDist End If If Not Rs Is Nothing Then Rs.ActiveConnection.Close '这一行关闭数据库连接。 Set Rs = Nothing End If FileCopy FSource, FDist End Sub
[此贴子已经被作者于2005-4-5 22:15:44编辑过]