ADODB Connection
Const connstring As String = "ConnectionString"
On Error GoTo ErrorHandler
Dim conn As ADODB.Connection
Set conn = New ADODB.Connection
conn.Open connstring
conn.Close
ErrorHandler:
If Err <> 0 Then
MsgBox Err.Source & "-->" & Err.Description, , "Error"
End If
ADODB Recordset
Const sql As String = "SELECT Field1, Field2 FROM Table1 WHERE Field3 = ?"
Const connstring As String = "ConnectionString"
Dim conn As ADODB.Connection
Dim cmd As ADODB.Command
Dim rs As ADODB.RecordSet
Set conn = New ADODB.Connection
conn.Open connstring
Set cmd = New ADODB.Command
With cmd
.ActiveConnection = conn
.CommandType = adCmdText
.CommandText = sql
.Parameters.Append .CreateParameter('Name', 'Type', 'Direction', 'Size', 'Value')
Set rs = .Execute
End With
conn.Close