Hi all,
I have a common dialog allowing the user to choose which access database (.mdb) to connect to. After a database file is selected the program will update the current connection by ADO:
Set Connecting = New ADODB.Connection
Connecting.Provider = "Microsoft.Jet.OLEDB.4.0"
Connecting.ConnectionString = "Data Source=" & DatabasePath
Connecting.Open
Sometimes the user may type the database name in the common dialog instead of picking by mouse, but if they spell wrong, the connection fails and the program crashs. So I do this coding to test if the database exists:
Private Sub Connecting_ConnectComplete(ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pConnection As ADODB.Connection)
If adStatus = adStatusErrorsOccurred Then
MsgBox "Cannot connect this database.", vbOKOnly + vbCritical
(Reopen the common dialog for the user to choose a correct database)
......
ElseIf adStatus = adStatusOK Then
MsgBox "Connection success.", vbOKOnly
......
End If
End Sub
I wonder if this is an "official" way to test the existence of a database. The flaw of this design is no matter the database path is working or not the connectionstring is changed/ruined (Since this is "ConnectComplete"). I want to know if ADO can just "test" the path but not doing any actual connection (tried using "willconnect" but it has no response). Any ideas?
I have a common dialog allowing the user to choose which access database (.mdb) to connect to. After a database file is selected the program will update the current connection by ADO:
Set Connecting = New ADODB.Connection
Connecting.Provider = "Microsoft.Jet.OLEDB.4.0"
Connecting.ConnectionString = "Data Source=" & DatabasePath
Connecting.Open
Sometimes the user may type the database name in the common dialog instead of picking by mouse, but if they spell wrong, the connection fails and the program crashs. So I do this coding to test if the database exists:
Private Sub Connecting_ConnectComplete(ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pConnection As ADODB.Connection)
If adStatus = adStatusErrorsOccurred Then
MsgBox "Cannot connect this database.", vbOKOnly + vbCritical
(Reopen the common dialog for the user to choose a correct database)
......
ElseIf adStatus = adStatusOK Then
MsgBox "Connection success.", vbOKOnly
......
End If
End Sub
I wonder if this is an "official" way to test the existence of a database. The flaw of this design is no matter the database path is working or not the connectionstring is changed/ruined (Since this is "ConnectComplete"). I want to know if ADO can just "test" the path but not doing any actual connection (tried using "willconnect" but it has no response). Any ideas?