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 42 43 44 45 46 47 48 49 50 51
| Option Explicit
EssaisConnexion
Sub EssaisConnexion
Dim Conn, strCnn, RqtSQL, Rst
On Error Resume Next
'Etape 1
Set Conn = CreateObject("ADODB.Connection")
If Err Then
MsgBox "Err N°" & Err.Number & vbNewLine & _
"Description:" & vbNewLine & vbNewLine & Err.Description, vbCritical, "Erreur création objet de connexion BDs"
Exit Sub
End If
'Etape 2
strCnn = "PROVIDER=Microsoft.ACE.OLEDB.12.0;Data Source=C:\PersoFrancis\Constructeur de requetes\BDpourEssais.mdb;" '*** adapter le chemin et nom ***
Conn.Open strCnn
If Err Then
MsgBox "Err N°" & Err.Number & vbNewLine & _
"Description:" & vbNewLine & vbNewLine & Err.Description, vbCritical, "Erreur ouverture BDs"
Set Conn = Nothing
Exit Sub
End If
'Etape 3
Set Rst = CreateObject("ADODB.Recordset")
If Err Then
MsgBox "Err N°" & Err.Number & vbNewLine & _
"Description:" & vbNewLine & vbNewLine & Err.Description, vbCritical, "Erreur création object RecordSet"
Set Conn = Nothing
Exit Sub
End If
'Etape 4 (si une table existe dans la BDs)
RqtSQL = "Select * From Principal" '*** adapter le nom de la table***
Rst.Open RqtSQL, Conn
If Err Then
MsgBox "Err N°" & Err.Number & vbNewLine & _
"Description:" & vbNewLine & vbNewLine & Err.Description, vbCritical, "Erreur ouverture table"
Set Rst = Nothing
Set Conn = Nothing
Exit Sub
End If
Set Rst = Nothing
Set Conn = Nothing
MsgBox "Tout est Ok", vbInformation, "Yes !!!"
End Sub |
Partager