Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    Jun 2001
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    File/Path Existence

    This should be simple, but it's not obvious to me. How can I test if a path exists?

    In Access 2000, How can I test if a file exists in that path? Rather than just trapping an error, I'd like to test for the existence of path/file and inform the user of their non-existence, if that be the case.

    Any thoughts would be greatly appreciated.

  2. #2
    Star Lounger
    Join Date
    Apr 2002
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: File/Path Existence

    One approach I use:

    ======================
    Dim strFileExists as String

    strFileExists = Dir(txtFilename)
    If strFileExists = "" Then
    . . . . .
    End If
    ======================
    What happens if the file exists is that the filename will be returned by the Dir function.

  3. #3
    New Lounger
    Join Date
    Jun 2001
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: File/Path Existence

    Thanks, that works just fine for files.

    What I found out is that for paths, particularly since a subdirectory might be empty, there is an optional second parameter:

    strFileExists = Dir(txtPathname, vbDirectory)

    will only return a zero-length string if the subdirectory doesn't exist. However, the result will be non-zero length if the directory exists, with or without any files in it.

    Again, thanks for pointing me in the right direction.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •