I'm doing a form with two fields, one with I can browse the path for a database and the other for the database password.
Everything working fine when it the right password and a path to a database file.
My problem is an error stop the program if I dont have the right password or the file is not a database. I'm not able to test the connection without crashing.
How can I test the path and the password without making the whole thing crash. Here a look of what I have done so far(very simple) :
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim canConnect As Boolean
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Jet OLEDB:Database Password=" & Me.txt2 & "; Data Source=" & Me.txt1 & ";"
Set rs = New ADODB.Recordset
If cn.State = adStateOpen Then
canConnect = True
cn.Close
End If
MsgBox canConnect
As you can see txt1 et txt2 are my two textarea and like I said everything crash before my message box prompt.