Two methods:
use FileSystemObject (Access 2002/03, not sure about previous versions):
Dim fs, f
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder("c:\temp")
MsgBox "Files: " & f.Count
or, use the Dir function:
Public Function CountFiles(DirName As String) As Integer
Dim i As Integer
DirName = IIf((Right(DirName, 1) = "\") Or _
(Right(DirName, 1) = "*"), _
DirName, DirName = DirName & "\")
i = 0
If Dir(DirName) <> "" Then
i = 1
Do While Not (Dir() = "")
i = i + 1
Loop
End If
MsgBox "There are " & i & " files in " & DirName
End Function
- Assaf