Season Greetings!

Searching database file in the application path

I want to determine the database file is existing or not... If the database (".mdb") is existing then msgbox "The database .mdb is not existing" if not existing msgbox " The database is not existing"

If the database is not existing... how to copy file of the existing database.

tnx in advance

10 Years
Discussion Span
Last Post by hkdani
If(System.IO.File.Exists(path As String) = true){
   MsgBox( message As String )
   FileCopy(Source As String, Destination As String)

System.IO.File.Exists is for .NET will not work in old VB versions
but here's a VB6 solution that works in my code.

Dim dir_str  As String
 'check if database exists (My_Database is a fully formed path+name)
dir_str = Dir(My_Database)
If dir_str = "" Then
   FileCopy My_DatabaseCopy, My_Database    'no database, get copy
    MsgBox "Database " & My_Database & " is ready."
End If

Edited by Dani: Fixed formatting


You need to use The File System Object. Add the Microsoft scripting runtime dll in your Project reference menu, first.

Option Explicit
Dim fso As FileSystemObject
Private Sub Form_Load()
Dim strFileName As String
Set fso = New FileSystemObject
strFileName = Text1.Text
If fso.FileExists(strFileName) Then
   MsgBox "Blah, Blah, Blah, the File exists", vbInformation, "File Status"
   MsgBox "Blah, Blah, Blah, the File does not exist.", vbInformation, "File Status"
End If
Set fso = Nothing
End Sub
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.