Results 1 to 3 of 3

Thread: Verifying if a file exists?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Verifying if a file exists?

    How do you verify if a spreadsheet file exists using VBA code within an Access environment. What I am trying to do is verify that a .xls file exists...if it doesn't then I need to create this file.

    I have no idea how to code VBA. I'm just a VB programmer and need some serious help with this.

    Thanks in advance,

    Blake

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Verifying if a file exists?

    I'm not sure if Access supports Dir, but in VB you could use the following:
    VB Code:
    1. If Dir("C:\folder\file.xls") = "" Then
    2.   'File doenst exist
    3. Else
    4.  'File does exist
    5. End If


    edit: corrected, thanks sciguyryan
    Last edited by si_the_geek; May 17th, 2005 at 05:07 PM.

  3. #3
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: Verifying if a file exists?

    Quote Originally Posted by si_the_geek
    I'm not sure if Access supports Dir, but in VB you could use the following:
    VB Code:
    1. If Dir("C:\folder\file.xls) = "" Then
    2.   'File doenst exist
    3. Else
    4.  'File does exist
    5. End If

    You missed a " in there, it should be:

    VB Code:
    1. If Dir("C:\folder\file.xls") = "" Then
    2.   'File doenst exist
    3. Else
    4.  'File does exist
    5. End If

    Cheers,

    RyanJ
    My Blog.

    Ryan Jones.

Posting Permissions

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



Click Here to Expand Forum to Full Width