Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2002

    Question Unanswered: Check to see if a file exists

    I need to create a file based on criteria supplied by a user. If the file creation is taking too long for whatever reason, I have it set to time out. How to I check to see if a file exists. I tried FileExists but i remember it not useful for my application (cant remember why tho).

    Thanx in advance

  2. #2
    Join Date
    Aug 2002
    Cambridge, England
    I wrote this code once to check whether a directory exists, you can edit it easily to check for a file.

    Sub Check_Output_File_Destination(DestinationString As String)
    ' Niall Staward 25/02/2002 - VBA MS Access XP
    ' This procedure checks whether a specified folder exists. If not it prompts the user
    ' to decide whether to create it
    Dim sFileDest As String
    Dim MyDir As String
    Dim Response As Integer

    sFileDest = DestinationString
    Response = 0

    MyDir = Dir(sFileDest, vbDirectory)

    If MyDir = "" Then
    ' Ask user whether to create dir
    Response = MsgBox("Specified Directory Not Found" & Chr(13) & _
    "Would you like to create:" & Chr(13) & sFileDest, _
    (vbYesNo + vbInformation + vbDefaultButton2), "Output Directory Invalid")

    If Response = vbYes Then Create_Any_Directory (sFileDest) 'Calls procedure to create the directory
    End If

    End Sub

  3. #3
    Join Date
    Jul 2002
    There is a function called Dir(arg1,arg2) I take it from your code, but is there a function for File(arg1,arg2)?

    From what I gather anyway, the method you go about doing it is to assign a string the directory name in question. If the string has no value, then the directory was not created. Is this correct?

Posting Permissions

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