Results 1 to 6 of 6
  1. #1
    4 Star Lounger
    Join Date
    Feb 2008
    Location
    United Kingdom
    Posts
    490
    Thanks
    0
    Thanked 0 Times in 0 Posts

    File not found (MSACCESS 2003)

    I have finally done a program to explore all folders and subfolders for word documents which then get stored in tables (Doc name and path)
    However I now have to do another part which runs through the table data checking those documents are still on the drive, if not then remove the database record.

    Is there an easy way to point to a file and if it's no longer there then deal with it in an if else statement without errors comming up that it cannot be found. Thanks

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: File not found (MSACCESS 2003)

    You can use the Dir function.:
    <code>
    Dim strFullName As String
    ' Code to get path and filename from table
    strFullName = ...
    ' Check whether file still exists
    If Dir(strFullName) = "" Then
    ' File doesn't exist - take appropriate action
    ...
    Else
    ' File exists
    ...
    End If</code>

  3. #3
    4 Star Lounger
    Join Date
    Feb 2008
    Location
    United Kingdom
    Posts
    490
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: File not found (MSACCESS 2003)

    Many thanks Hans, that will do nicely. Regards

  4. #4
    4 Star Lounger
    Join Date
    Feb 2008
    Location
    United Kingdom
    Posts
    490
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: File not found (MSACCESS 2003)

    Any idea why this does not work. I have six directory names under the directory of Documents. It reports some directory names are found and others that cannot be found, however they are there? Thanks

    SQL = "Select * From tblDirectory ORDER BY MainDirName"
    Set rst = db.OpenRecordset(SQL, dbOpenDynaset)

    Do While Not rst.EOF

    strFullName = "kOCUMENTS" & rst("MainDirName") & ""

    If Dir(strFullName) = "" Then
    ' File doesn't exist - take appropriate action
    MsgBox "File Does Not Exist " & strFullName
    Else
    ' File exists
    MsgBox "File Exists " & strFullName
    End If

    rst.MoveNext
    Loop

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: File not found (MSACCESS 2003)

    Try

    If Dir(strFullName, vbDirectory) = "" Then

    The message box text is confusing since you're looking for folders not files.

  6. #6
    4 Star Lounger
    Join Date
    Feb 2008
    Location
    United Kingdom
    Posts
    490
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: File not found (MSACCESS 2003)

    Many thanks Hans, that fixed it. Best regards

Posting Permissions

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