referencing filelen with a path

sha7jpm

Registered User.
Local time
Today, 17:41
Joined
Aug 16, 2002
Messages
205
hi,

I am stuck on the filelen() command within access..

within vb I have the path stored and then I need filelen to tell me the size of the file which the path depicts..

I have :

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
.Execute

'Count the files found
intcount = 0
mylength = "h:\" & Me!ProjectsCode & "\" & Me!Expr1 & "*.rdf"
FileLen (mylength)
For Each varFile In .FoundFiles
intcount = intcount + 1
Next varFile
End With
Else
End If
Me.Text9 = intcount
Me.Text10 = mylength
End Sub

this all works fine, mylength returns the pathname perfectly..
except that filelen does not like 'mylength'
it brings up an error run time 52, bad name or number...

I have seen in other threads the use of fillen with a ref such as filelen(strfile), so it must be possible...

many thanks in advance..

John.
 
You need to assign the return value of the FileLen function to a variable. Right now the FileLen function is just hanging out with no where to go.

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
.Execute

'Count the files found
intcount = 0
mylength = "h:\" & Me!ProjectsCode & "\" & Me!Expr1 & "*.rdf"
mysize=FileLen (mylength)
For Each varFile In .FoundFiles
intcount = intcount + 1
Next varFile
End With
Else
End If
Me.Text9 = intcount
Me.Text10 = mylength


Did you want to assign the length of the file to text10?
 
You need to assign the return value of the FileLen function to a variable. Right now the FileLen funciton is just hanging out with no where to go.

Dim intcount As Integer, varFile As Variant, objFileFind As Object, mysize As Long, mylength As String
Dim theLength

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
.Execute

'Count the files found
intcount = 0
mylength = "h:\" & Me!ProjectsCode & "\" & Me!Expr1 & "*.rdf"
theLength=FileLen (mylength)
For Each varFile In .FoundFiles
intcount = intcount + 1
Next varFile
End With
Else
End If
Me.Text9 = intcount
Me.Text10 = thelength


Did you want to assign the length of the file to text10?
 
cheers!

a big thanks for your help,

I feel very stupid about not realising that I needed to assign the variable!

have put in the changes to the code but am still having a runtime error 52, bad name or number.
relating to the filelen line...

its all very strange... do you need to define the var?

i.e. dim thelength as string?

thanks for your help on this..

John
 
sorry I also meant to add,

yes, at present I am filling text10 with the value of thelength...

but as a final product I want to be able to return the amount of files over a certain size..

so that the routine only counts the files that are eg.. 50kb or bigger..

ta

John.
 
weird...I edited my post and somehow you got both versions.

I'll post again

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
.Execute

'Count the files found
intcount = 0
mylength = "h:\" & Me!ProjectsCode & "\" & Me!Expr1 & "*.rdf"
mysize=FileLen (mylength)
For Each varFile In .FoundFiles
intcount = intcount + 1
Next varFile
End With
Else
End If
Me.Text9 = intcount
Me.Text10 = mylength
 
thanks for the amended version...

I have tried it, but still get a error with the filelen..

runtime 52, bad name or number...

it just does not seem to like the process of giving mysize the value of filelen...

maybe it is due to the fact that filelen seems to be only used with a specified path..

all the helpfiles give examples of :
filelen("c:\temp\temp.sav")

not where you define the path earlier and store it under 'mylength' and connect that to filelen..

this certainly is frustrating! I really appreciate all your help..
 

Users who are viewing this thread

Back
Top Bottom