Several readers responded with their suggestions for determining if a database exists.
Thomas Mount responded to my tip on finding out whether a file exists in WAW 6.07, with a more efficient method using the FileSystemObject:
Function isFile(FileName as String) as Boolean
isFile = _
CreateObject(“Scripting.FileSystemObject”).FileExists(FileName)
End Function
This method is indeed more efficient. I often use the FileSystemObject to work with files in my code samples. The only drawback is that it requires setting a reference to the Microsoft Scripting Runtime library.
Cameron Knox also contributed a function using the FileSystemObject:
Public Function TestFileExists(strFile As String) As Boolean
Dim fso As New Scripting.FileSystemObject
Dim fil As Scripting.File
On Error Resume Next
Set fil = fso.GetFile(strFile)
If fil Is Nothing Then
TestFileExists = False
Else
TestFileExists = True
End If
End Function
If your database has a reference set to the Microsoft Scripting Runtime library, you can use one of these functions to determine whether a file exists.
Finally, John Allcock contributed a one-line function that uses the old Dir function, and thus does not require a reference to the Microsoft Scripting Runtime library.
Public Function TestFileExists(strFile as string) as Boolean
On Error Resume Next
TestFileExists = Not (Dir(strFile) = “”)
End Function