Private mdbBaseDatos As ADODB.Connection
Public Sub AbrirBaseDatos(ByVal strRuta As String, Optional ByVal strPassword As String, Optional ByRef blnErrAbrir As Boolean)
Dim strCadConexion As String
On Error GoTo ErrorAlAbrir
Set mdbBaseDatos = New ADODB.Connection
strCadConexion = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
strRuta & ";"
If Len(strPassword) Then
strCadConexion = strCadConexion & "Jet OLEDB:Database Password=" & _ strPassword & ";"
End If
mdbBaseDatos.CursorLocation = adUseClient
mdbBaseDatos.Open strCadConexion
blnErrAbrir = False
On Error GoTo 0
Exit Sub
ErrorAlAbrir:
MsgBox "Error al inicializar la conexión a la base de datos" & vbCrLf & _
vbCrLf & "Información de error" & vbCrLf & "Numero: " & Err.Number & _
vbCrLf & "Descripción: " & Err.Description, vbCritical + _
vbOKOnly, "Error fatal"
blnErrAbrir = True
On Error GoTo 0
End Sub