Verify file name exist from table field

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • timleonard
    New Member
    • Jun 2010
    • 52

    Verify file name exist from table field

    Is it possible and if so, how?

    Would like to have code to verify that a file name in a same directory matches with the file name in a table/ field. If it matches then run the rest of the code, if not prompt with error.

    Can someone give me some pointer how this should be written

    Thanks for any help you could offer
  • timleonard
    New Member
    • Jun 2010
    • 52

    #2
    Found something that may work.

    Code:
    Dim fso
    Dim file As String
    file = strXLFile   ' change to match the file w/Path
    Set fso = CreateObject("Scripting.FileSystemObject")
    If Not fso.FileExists(file) Then
        MsgBox file & " was not located.", vbInformation, "File Not Found"
    Else
        MsgBox file & " has been located.", vbInformation, "File Found"
    End If
    Still open to any other suggestions

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32653

      #3
      I would start with the field value in the table. The current folder can be found from CurrentProject. FullName if you remove the name part. Add the value from the field to this and use the Dir() function to determine if it does indeed exist.

      Using FileSystemObjec t is an alternative, but I would say it's more complicated and requires a library reference which is less standard than the VBA one which is common to all projects.

      Comment

      • timleonard
        New Member
        • Jun 2010
        • 52

        #4
        Originally posted by NeoPa
        I would start with the field value in the table. The current folder can be found from CurrentProject. FullName if you remove the name part. Add the value from the field to this and use the Dir() function to determine if it does indeed exist.

        Using FileSystemObjec t is an alternative, but I would say it's more complicated and requires a library reference which is less standard than the VBA one which is common to all projects.
        Excellent Suggestion...
        I am trying the following and it works

        Code:
        If Len(Dir(strXLFile)) = 0 Then
                MsgBox "Could not find " & strXLFileName & ", Check the " & strCurrentDir & " Folder and the Paths Setup to be sure the file names match.", vbInformation, "File Not Found"
                GoTo Exit_Sub
            Else
               'Continue through the code
            End If
        Last edited by timleonard; Jun 18 '10, 06:11 AM. Reason: Typo

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32653

          #5
          Glad you got it working Tim. I'd suggest replacing line #5 (Else) with line #7 (End If), but that's just semantics.

          Comment

          Working...