'Referencia: ADO 2.8
Dim conexdb As ADODB.Connection
Dim rs As ADODB.Recordset
Private Sub Form_Load()
Dim Servidor As String
Dim BaseDatos As String
Dim Usuario As String
Dim Password As String
Dim SQL As String
Dim Conexion As String
Servidor = "localhost"
BaseDatos = "agenda_db"
Usuario = "admin"
Password = "123456789"
SQL = "Select * From agenda_tb"
Conexion = "DRIVER={MySQL ODBC 3.51 Driver};"
Conexion = Conexion & "SERVER=" & Servidor & ";"
Conexion = Conexion & "PORT=3306;"
Conexion = Conexion & "DATABASE=" & BaseDatos & ";"
Conexion = Conexion & "USER=" & Usuario & ";"
Conexion = Conexion & "PASSWORD=" & Password & ";"
Conexion = Conexion & "OPTION=3;"
Set conexdb = New ADODB.Connection
conexdb.ConnectionString = Conexion
conexdb.CursorLocation = adUseClient
conexdb.Open
If conexdb.State > 0 Then
Set rs = New Recordset
rs.Open SQL, conexdb, adOpenStatic, adLockOptimistic
Else
MsgBox "No se ha podido realizar la Conexión con la Base de Datos", vbInformation, "Fallo la Conexion"
Unload Me
End If
End Sub