読者です 読者をやめる 読者になる 読者になる

φ(..) ビボ~6 φ(..)

主にAccess、VBAに関する備忘録

FileSystemObjectで並べ替え

MS Access
Const adInteger = 3
Const adDate = 7
Const adFldIsNullable = 32
Const adVarChar = 200

Dim rs

Dim fs
Dim fsFolder
Dim fsFile

Set rs = CreateObject("ADODB.Recordset")

rs.Fields.Append "myname", adVarChar, 300, adFldIsNullable
rs.Fields.Append "mydate", adDate, , adFldIsNullable
rs.Open

Set fs = Server.CreateObject("Scripting.FileSystemObject")
Set fsFolder = fs.GetFolder("n:\Test")

For Each fsFile In fsFolder.Files
    rs.AddNew
    rs(0).Value = fsFile.Name
    rs(1).Value = fsFile.DateLastModified
    rs.Update
Next

rs.Sort = "myname ASC"
rs.MoveFirst

Do Until rs.EOF
    Debug.Print rs.Fields(0)
    rs.MoveNext
Loop

rs.Close
Set rs = Nothing