Question Test if a file exists

Kobus-Dippenaar

Registered User.
Local time
Today, 08:48
Joined
Oct 10, 2014
Messages
50
Good day to all,


I have a simple query reading the records in a table and testing if the link on file has a folder\file on disc.

I get alternative messages that both entries does exist and when I run the report again I would get both not to exist.
(Only two records on file)
The truth is only the d:\0000 path exists on my D drive.

The query has an event procedure on load with the following code:

Private Sub Report_Load()
Dim xdir As String
xdir = Dir(Me.Link)
If xdir <> "" Then
Me.Text9 = "file does exist"
Else
Me.Text9 = "file does not exist"
End If
End Sub


I welcome your feedback.
Thanks
Kobus
 
OK Guys and Girls,
I got it to work with a little help from my friend.
The code to check the existence of the file has to be a Public Function (Module coding)
See:
Public Function FileNotice(Filecheck) As String

Dim XDir As String
XDir = Dir(Filecheck)
If Len(XDir) > 0 Then
FileNotice = "File does exist."
Else
FileNotice = "File does not exist."
End If

End Function


In the query you call this function from a "cell"
Notice: FileNotice([Link])
Link is a field in the query to be tested.


Hope it makes sense.
 
Or you could do this in code...
Code:
Public Function FileExists(Filename) As Boolean
    FileExists = Len(Dir(Filename))
End Function
And this in the query...
Code:
Notice: "File does " & IIF(Not FileExists([Link], "not ", "") & "exist."
Mark
 
OK Guys and Girls,
I got it to work with a little help from my friend.

Your friend being various people who contributed answers at another forum (UA).
In future, if you cross post at more than one site, please state you have done so and provide the link at both sites. See this link for an explanation of why it matters https://www.excelguru.ca/content.php?184
 

Users who are viewing this thread

Back
Top Bottom