Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2002
    Location
    South Wales
    Posts
    580

    Unanswered: Does A File / Path Exist VBA

    Can anyone help me with this snippet of code???

    I have an access continuous form which displays a list of job numbers

    Next to each job number are 3 buttons which will hopefully link to an external file > drawing / quote / costing sheets associated with that job.

    The code attempts to load the lastest version of the associated file for
    that job

    Say for the costing sheet...

    Private Sub cmdOpenCostingSheet_Click()

    Me.cmdOpenCostingSheet.HyperlinkAddress = "\\GDSERVER\DATA\Estimates\files\" & [X Number] & [LastOfISSUE_NUMB] & ".123"

    End Sub

    This code works fine and will open the file if its in the right place....

    HOWEVER
    the path and filename "guesses" the location of the file (Basically, it sets the Hyperlink to the location that the file SHOULD be in...

    However, I would like to add an error-trap in case the file is NOT where it should be to avoid the default error message

    "!Unable to open (path) Cannot open the specified file."

    Can anyone make a suggestion how to do this or alternitively a better method of solving the same problem.

    Many thanks


    Gareth Dart

  2. #2
    Join Date
    Jul 2002
    Posts
    67
    What error number are receiving if any? You could right an error handler routine to handle this error number.

    Code:
    On error GoTo errHandler
    
    
    <<  Main Code Here  >>
    
    
    errHandler:
         Select Case err.Number
              Case <<"Error Number Here">>
                    MsgBox "The file you are requesting has been moved" & vbCrlLf 
                                &" or no longer exists.",vbExclamation,"File Not Found".
                     Exit Sub
        End Select
    Hope this helps.
    Don't do today, what can be done tomorrow.

  3. #3
    Join Date
    Aug 2002
    Location
    Québec, Canada
    Posts
    109
    You can use FileSystemObject to check if a file exist. Make sure you add a reference to Microsoft Scripting runtime:

    Code:
        'Add a reference to Scripting Runtime
        
        Dim fso As New FileSystemObject
        
        If fso.FileExists("C:\Jeff\FICHTEST.txt") Then
            MsgBox "That file exist"
        Else
            MsgBox "Do not exist"
        End If
    
        set fso = nothing
    JefB - hope it helps

  4. #4
    Join Date
    Sep 2002
    Location
    South Wales
    Posts
    580

    Thumbs up Thanks both

    Jeff thats exaclty what I was after...many 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
  •