Results 1 to 5 of 5

Thread: Check to see if file exists (Resolved - thanks!)

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2002
    Posts
    78

    Question Check to see if file exists (Resolved - thanks!)

    Thank you to everyone that replied and provided solutions. I tried Beacon's and stingrae's suggestions because that way I will gain double the knowledge!!! However, I couldn't get Beacon's to work but I'm sure it was something that I did wrong. Stingrae's worked after I found the correct library to reference -- Microsoft Scripting Runtime, which is probably a necessity for all programs (this is where my VB naivity gets me!).

    Ecniv -- I'll work on the Dir$ function later, I referenced the help section and it looked a bit more complicated but very useful so I'll check it out when I'm not under this intense deadline (or when I find myself in yet another pickle and have to!!!).

    Once again, thanks everyone for getting me out of my newest pickle.

    "I know enough VB to get myself into trouble, but not enough to get out of it!"

    Take care,
    Mary

    ************************************************
    Good evening everyone!

    I tried searching but can't narrow this down enough to weed through it all and I need to find this faster....

    I have a report via Crystal Report designer, it's working great, and I have even managed to get it to export to Word (with the help of an earlier posting!), but if I run it a second time I get an error because the file already exists. This file can be replaced or deleted first then the new one can be created.... how can I check for the existance of the file to kill it before I export the report again?

    I know it has something to do with file or system objects but that's as far as I've gotten in my haste... I will keep looking in the meantime but if someone can point me to an earlier post or something that would be greatly appreciated!!!

    Thank you so much once again!!
    Mary
    Last edited by A441OTA; Jul 31st, 2002 at 08:14 AM.

  2. #2
    PowerPoster Beacon's Avatar
    Join Date
    Jan 2001
    Location
    Pub Floor
    Posts
    3,188
    Use:

    VB Code:
    1. Private Function FileExists(ByVal sFile As String) As Boolean
    2. 'lets use this to check if the file exists before we make it hey
    3.     FileExists = CBool(Len(Dir$(sFile)))
    4. End Function

    Usage:
    VB Code:
    1. If fileexists = True then
    2. Kill filenamehere
    3. end if

    good luck
    b

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2002
    Posts
    78

    thanks Beacon!

    Thanks so much Beacon, I'll try it first thing in the morning!!!

    You're awesome!!!


  4. #4
    Hyperactive Member stingrae's Avatar
    Join Date
    Apr 2002
    Location
    Sydney
    Posts
    401
    This works too:

    Code:
        Dim fso As New FileSystemObject
        If fso.FileExists(sFile) = True Then
            Kill sFile
        End If
    "The passion lives to keep your faith, though all are different, all are great" ... Michael Hutchence 1960-1997.

    Windows & Web Developer
    Specialising in Visual Basic .Net & Client Server Programming & Client/Customer Relations Databases
    Sutherland Shire, Sydney Australia
    www.stingrae.com.au
    Developer of Arnold - Gym & Martial Arts Database Management System
    www.gymdatabase.com.au

  5. #5
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343
    Or for the vb version ... look at the Dir$ function (although this is just a wrapper of VB for Beacons posting.


    Vince

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

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