|
从数据库“备份”表里读出源文件与目标文件夹是,然后在目标文件夹里存20个备份文件,循环备份。请高手指教下面的代码错误,如何修改。
Dim conn As ADODB.Connection
Set conn = CurrentProject.Connection
Dim rst As New ADODB.Recordset
Dim strsql As String
Dim TemPath As String
Dim StrFileName As String
Dim strDBFileName As String
strsql = "SELECT top 1 源文件, 备份文件 FROM 备份"
rst.Open strsql, conn, 1, 1
If Not IsNull(rst("源文件")) And Not IsNull(rst("备份文件")) Then
strDBFileName = Format(Year(Now), yyyy) & Format(Month(Now), mm) & Format(Day(Now), dd) & Format(Hour(Now), hh) & Format(Minute(Now), mm) & ".mdb"
Dim fs
Set fs = Application.FileSearch
TemPath = rst("备份文件") & "\"
fs.LookIn = rst("备份文件")
fs.Filename = "*.mdb"
If fs.foundfiles.Count > 20 Then
StrFileName = DMin(Left(fs.Filename, 12))
Kill TemPath & StrFileName & ".mdb"
End If
FileCopy rst("源文件"), TemPath & strDBFileName
End If
rst.Close
Set rst = Nothing
Set conn = Nothing |
|