Folder

A

Assaf

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top