I have been struggling with this Filelen problem, and was then happy that I work out what the problem ws, but unhappy because I am still unclear on how to sort this out!
I previously had a problem with filelen, I was running a search on a directory and returning a count of files which matched a certain filename. that was fine.
Then my boss asked me to specify the criteria further by counting only those over a certain size. I tried this but because the syntax is looking at all files which match a *.rdf search, not a fixed file, the filelen falls over.
so I looked at putting the list of files into a recordset and counting them if they were over a certain size.
so my Q's are.. how do I get the data into the recordset, (which is proving very difficult) and does anyone know how to hold the filesize which of course filelen will need.
hope I have not made this thread completely confused!
my code is (please see below)
thanks John.
Option Compare Database
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Dim intcount As Integer, varFile As Variant, objFileFind As Object, mysize As Long, mylength As String
Set objFileFind = Application.FileSearch 'FindFiles
'Find the Files
If Me!Expr1 <> "" Then
With objFileFind
.NewSearch
.FileName = Me!Expr1 & "*.rdf" 'or whatever you want to find
.LookIn = "h:\" & Me!ProjectsCode
.SearchSubFolders = False 'if you have subfolders to search also
mylength = "h:\" & Me!ProjectsCode & "\" & Me!Expr1 & "*.rdf"
mysize = FileLen(mylength)
.Execute
'Count the files found
intcount = 0
For Each varFile In .foundfiles
'HERE I THINK I NEED TO STORE THIS IN THE RECORDSET, BUT CANNOT SEEM TO HOLD THE FILELENGTH
mysize = FileLen(mylength)
if mysize < 20kb then
intcount = intcount + 1
Debug.Print varFile
Next varFile
End With
Else
End If
Me.Text9 = intcount
Me.Text10 = mylength
End Sub
I previously had a problem with filelen, I was running a search on a directory and returning a count of files which matched a certain filename. that was fine.
Then my boss asked me to specify the criteria further by counting only those over a certain size. I tried this but because the syntax is looking at all files which match a *.rdf search, not a fixed file, the filelen falls over.
so I looked at putting the list of files into a recordset and counting them if they were over a certain size.
so my Q's are.. how do I get the data into the recordset, (which is proving very difficult) and does anyone know how to hold the filesize which of course filelen will need.
hope I have not made this thread completely confused!
my code is (please see below)
thanks John.
Option Compare Database
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Dim intcount As Integer, varFile As Variant, objFileFind As Object, mysize As Long, mylength As String
Set objFileFind = Application.FileSearch 'FindFiles
'Find the Files
If Me!Expr1 <> "" Then
With objFileFind
.NewSearch
.FileName = Me!Expr1 & "*.rdf" 'or whatever you want to find
.LookIn = "h:\" & Me!ProjectsCode
.SearchSubFolders = False 'if you have subfolders to search also
mylength = "h:\" & Me!ProjectsCode & "\" & Me!Expr1 & "*.rdf"
mysize = FileLen(mylength)
.Execute
'Count the files found
intcount = 0
For Each varFile In .foundfiles
'HERE I THINK I NEED TO STORE THIS IN THE RECORDSET, BUT CANNOT SEEM TO HOLD THE FILELENGTH
mysize = FileLen(mylength)
if mysize < 20kb then
intcount = intcount + 1
Debug.Print varFile
Next varFile
End With
Else
End If
Me.Text9 = intcount
Me.Text10 = mylength
End Sub