Results 1 to 6 of 6
  1. #1
    Bronze Lounger
    Join Date
    Feb 2001
    Location
    Escondido, California, USA
    Posts
    1,458
    Thanks
    0
    Thanked 1 Time in 1 Post

    Detecting bad filespec (Access 2000)

    How can I detect a bad filespec without causing a Run Time error? I am using Dir(filespec) which returns an empty string if it cannot find the filespec, BUT this assumes that it is a legal filespec, i.e. somthing like C:folder1folder2filename.ext. I sometimes run into the case where the filespec is not in the proper form, i.e. something like C:folder1G:filename.ext. In this case the Dir function causes a Run Time error. I need to detect that it is not a legitimate filespec and so inform the user without creating a Run Time error.

  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Detecting bad filespec (Access 2000)

    You can put an error handler in your code and test on the error number. The error for a bad directory is 52.
    Here a simple sample of this.
    <pre>Function testdir()
    On Error GoTo ErrHandler
    Dim Directory As String
    Directory = "d:c:atest.xls"
    Debug.Print Dir(Directory)
    Exit Function
    ErrHandler:
    If Err.Number = 52 Then
    MsgBox "This directory " & Directory & " don't exist"
    Else
    MsgBox Err.Number & " " & Err.Description
    End If
    End Function</pre>

    Francois

  3. #3
    Bronze Lounger
    Join Date
    Feb 2001
    Location
    Escondido, California, USA
    Posts
    1,458
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Detecting bad filespec (Access 2000)

    Thanks Francois -- that does it quite nicely.

    By the way, is there some place one can go (the help file?) to find a listing of all these error numbers and what they mean?

  4. #4
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Detecting bad filespec (Access 2000)

    I don't know for a list.
    I use the error handler routine without If Then Else using just
    MsgBox Err.Number & " " & Err.Description
    Put a breakpoint after this line and in the immediate window I type
    ? err.number
    wich give me the number I have to catch in the If Then Else
    Francois

  5. #5
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Detecting bad filespec (Access 2000)

    Francois

  6. #6
    Bronze Lounger
    Join Date
    Feb 2001
    Location
    Escondido, California, USA
    Posts
    1,458
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Detecting bad filespec (Access 2000)

    WOW! After eliminating all the "No Error" entries the list still comes to 4250 error messages! Of course, a lot of them are repeats, but there's still a ton of the things.

    Thanks for your help.

Posting Permissions

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