Results 1 to 4 of 4
  1. #1
    jnrussell is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Feb 2014
    Posts
    17

    Trying to test if a file exists with no luck

    I'm trying to test if a file exists, then display a message if it doesn't. The code I'm entering does not work at all. What am I doing wrong?



    Dim MyPath As String
    MyPath = CurDir()

    Dim strfilename As String
    strfilename = MyPath & "\Instructions%20for%20CAFP%20Inventory%20Program. doc"

    If strfilename = "" Then
    MsgBox "File does not exist"

    End If

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Check the FileSystemObject

    It has a method -- here's a typical usage
    Code:
    ........
    ' Check to make sure the file exists...
    If fso.FileExists(BodyFile$) = False Then
    MsgBox "The body file isn’t where you say it is. " & vbNewLine & vbNewLine & _
    "Quitting...", vbCritical, "I Ain’t Got No-Body!"
    ..........

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Another method that doesn't require declaring fso object variable:

    If Dir("path\filename") = "" Then MsgBox "your message"
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    jnrussell is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Feb 2014
    Posts
    17
    That last one worked! I was hoping for something simple like that. Thank you!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. If statement depending if a file exists
    By mike02 in forum Access
    Replies: 1
    Last Post: 06-11-2013, 09:35 AM
  2. RunSavedImportExport file exists
    By BettyJordan in forum Access
    Replies: 1
    Last Post: 11-27-2012, 02:55 PM
  3. Checking beforehand whether a file exists
    By Ronald in forum Programming
    Replies: 2
    Last Post: 07-27-2011, 08:48 AM
  4. How to test of record exists in table?
    By tdaccess in forum Access
    Replies: 3
    Last Post: 04-13-2011, 10:22 AM
  5. How to tell if a file exists and then delete it
    By orcinus in forum Programming
    Replies: 3
    Last Post: 05-17-2010, 05:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums