Skip to content

How to Determine if a Database Exists

Here’s a function to determine whether a database exists on a network drive.

Q:  Glenn Faber writes that he needs a function that determines whether a database exists, on a network drive.  If it exists (i.e., the network drive is available), a number of instructions will be run; otherwise, they won’t be run.

 

A:  Here is a function I use for this purpose (it works with any file, not just databases).  You need a reference to the Microsoft Scripting Runtime library to use the function.

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

 

The strFile argument takes the full file path and name of the database (such as “N:DocumentsDevelopmentMarsFCFFCF.mdb”)

About this author

Office 2024 - all you need to know. Facts & prices for the new Microsoft Office. Do you need it?

Microsoft Office upcoming support end date checklist.