1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
Private Sub Test_ADO()
Const DB_PATH As String = "Z:\Tests\Comptoir.mdb"
Const CONNECTION_STRING As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DB_PATH & ";"
Const MY_QUERY As String = "SELECT * FROM Clients WHERE [Code client]='ALFKI'"
Dim oCnx As ADODB.Connection
Dim oRs As ADODB.Recordset
On Error GoTo L_ErrTest_ADO
Set oCnx = New ADODB.Connection
oCnx.Open CONNECTION_STRING
Set oRs = New ADODB.Recordset
With oRs
Set .ActiveConnection = oCnx
.Source = MY_QUERY
.LockType = adLockOptimistic
.CursorType = adOpenKeyset
.Open
If Not .EOF Then
MsgBox "Le code 'ALFKI' fait référence au client : " & .Fields("Société") & ".", vbInformation
Else
MsgBox "Le code 'ALFKI' fait référence à aucun client !", vbExclamation
End If
.Close
End With
oCnx.Close
Set oCnx = Nothing
Set oRs = Nothing
On Error GoTo 0
L_ExTest_ADO:
Exit Sub
L_ErrTest_ADO:
MsgBox Err.Description, 48, Err.Source
Resume L_ExTest_ADO |
Partager