Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2003
    Posts
    36

    Unanswered: check for a file

    Hi

    I need a bit of code to check for a file and if it exists run a query. Can someone point me in the right direction. the file is on a networked server too.

    Thanks

    Nicky

  2. #2
    Join Date
    Mar 2003
    Location
    UK
    Posts
    71
    With Application.FileSearch
    .SearchSubFolders = True 'Searchsubfolders set to false if not wanted
    .LookIn = "C:\DirectoryName"
    .FileName = "filename.extension"
    If .Execute() > 0 Then 'if file exist
    DoCmd.OpenQuery "qryname"
    Else
    Whatever you want - prob nothing
    End If
    End With
    Last edited by emma_com; 09-02-03 at 10:17.

  3. #3
    Join Date
    Mar 2003
    Posts
    36
    thanks for that I'll give it a shot

  4. #4
    Join Date
    May 2002
    Location
    London
    Posts
    87
    If you just want to check if a file exists, this function will do:
    Code:
    Public Function CheckFilePath(strPath) As Boolean
    Dim fso As Scripting.FileSystemObject
    Set fso = New FileSystemObject
    CheckFilePath = fso.FileExists(strPath)
    Set fso = Nothing
    End Function
    Remeber to reference in "Microsoft Scripting Runtime".

  5. #5
    Join Date
    Jul 2003
    Posts
    38
    There is another way, without using external references, and only one line of code:

    Public Function FileExist(datei As String) As Boolean
    On Error GoTo err_file

    FileExist = Dir$(datei) <> ""

    exit_file:
    Exit Function
    err_file:
    MsgBox err.Description
    Resume exit_file
    End Function

Posting Permissions

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