What should DIR("") return?

  • Thread starter Thread starter ApexData
  • Start date Start date
A

ApexData

Hi

I am using the following statement to check for a file:

If Len(Dir(strFileName)) = 0 Then
'Not Found'
Endif

The problem is if strFileName = "" then
MsgBox Dir(strFileName) 'returns the name of some combobox that does
not even exists in my project, but does exist in an old project.
Before we cry corruption, does Dir("") return a legitimate value???

Thanks Greg
 
Dir returns the name of a combobox? Dir is used to obtain the file name of a
file in a specified path; not sure what that has to do with a combo box?

You can test whether Dir("") will return a value by trying it in the VBE
Immediate Window. You'll find that it may return the name of a file in some
"root" directory, probably depending upon what the path was to which ACCESS
last navigated, but.....

Just test strFileName for when it's equal to "" and then bypass the code:

If strFileName<>"" Then
If Len(Dir(strFileName)) = 0 Then MsgBox "Not Found"
End If
 
I discovered that Dir("") had returned a file in the MyDocuments
Folder.
It appears that it had returned the .mdb file found first there
alphabetically.
When I used Len(Dir(strFileName)), and the strFileName was zero len, I
would have expected the results to have been 0. But, obviously not
the case.
 
It works the same as the Windows call it maps to, which
works the same as the old DOS internal function it replicates.

That is, if you go to a command prompt and type
DIR abc
and press enter, you get the file "abc" if one exists. If you
just type
DIR
with nothing following it and press enter, you get a listing
of all the files and folders in the current folder.

(david)
 
I believe I understand what was happening now.
I could work around it, but it became futher complicated by the use of
UNC paths, in that errors would arise when checking for the BackEnd
data. I am now using the following code which resolved the matter,
and have further included a less responsive error handler.

If GetAttr(strFileName) And vbDirectory Then
'it's a directory or does not exist
FileExists = False
Else
FileExists = True
End If
On Error GoTo 0

ThankYou
Greg
 
Back
Top