设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 1293|回复: 5
打印 上一主题 下一主题

[Access本身] 如何用代码找出文件夹中最早保存的文件名?

[复制链接]
跳转到指定楼层
1#
发表于 2008-1-29 17:03:44 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
找出文件夹中最早保存的文档的代码怎么写,请高手指教!
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
2#
 楼主| 发表于 2008-1-29 21:19:45 | 只看该作者
Private Sub Form_Load()
Dim conn As ADODB.Connection
    Set conn = CurrentProject.Connection
    Dim rst As New ADODB.Recordset
    Dim strsql As String
    Dim TemPath As String
    Dim strDBFileName As String
    strsql = "SELECT  top 1 源文件, 备份文件 FROM 备份"
    rst.Open strsql, conn, 1, 1
if not rst.eof then
If Not IsNull(rst("源文件")) And Not IsNull(rst("备份文件")) Then
        strDBFileName = Year(Now()) & Month(Now()) & Day(Now()) & Hour(Now()) & Minute(Now()) & ".mdb"
       TemPath = rst("备份文件") & "\"
          FileCopy rst("源文件"), TemPath & strDBFileName
    End If
end if
   rst.Close
    Set rst = Nothing
    Set conn = Nothing
End Sub
以上是我备份的代码我想在这代码中加入只保存20个备份的循环保存方法,就是在 rst("备份文件") 的文件夹中如果超过20个就删除第一个保存的文档。
        Set fs = Application.FileSearch
        fs.LookIn = rst("备份文件")
        fs.FileName = "*.mdb"
if fs.FoundFiles.Count >=20 then  删除第一个保存的文档,请高手指教完整

[ 本帖最后由 小铁匠 于 2008-1-29 21:25 编辑 ]
3#
发表于 2008-1-29 23:38:25 | 只看该作者
值得详细研究一下!谢谢
4#
 楼主| 发表于 2008-1-30 11:35:13 | 只看该作者
没人给我回复吗?求教高手指点!!!
5#
发表于 2008-1-30 12:50:49 | 只看该作者
Dim TemPath As String
Dim StrKey As String
Dim Tem As String
Set fs = Application.FileSearch
TemPath = CurrentProject.Path & "\bak\"

With fs

.LookIn = CurrentProject.Path & "\bak"
.FileName = "*.mdb"

If .Execute > 0 Then

IntTem = Year(Now()) & Month(Now()) & Day(Now()) & Hour(Now()) & Minute(Now())

If .FoundFiles.Count > 3 Then

For I = 1 To .FoundFiles.Count

StrKey = Right(fs.FoundFiles(I), Len(fs.FoundFiles(I)) - Len(TemPath)) 'filename
StrKey = Left(StrKey, Len(StrKey) - 4)


If IntTem > StrKey Then
IntTem = StrKey
End If

Next I

If IntTem <> Year(Now()) & Month(Now()) & Day(Now()) & Hour(Now()) & Minute(Now()) Then
Kill TemPath & IntTem & ".mdb"
End If

End If

End If
End With
6#
发表于 2008-1-30 12:52:07 | 只看该作者
If .FoundFiles.Count > 3 Then   这里根据情况修改
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-5-22 14:36 , Processed in 0.112734 second(s), 29 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表