Sub ConnecterBase(ConnectBD As ADODB.Connection, _
CheminBD As String, _
Optional Rs)
Set ConnectBD = New ADODB.Connection
If Not IsMissing(Rs) Then
Set Rs = New ADODB.Recordset
End If
With ConnectBD
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = CheminBD
.Open
End With
End Sub
Sub Requete(Req As String)
Dim ConnectBD As ADODB.Connection
Dim Rs As ADODB.Recordset
Dim ChaineSQL As String
ChaineSQL = "select ((T2.'GEST' || TO_CHAR(TRUNC(T2.'NU_CDE' ))) || TO_CHAR(TRUNC(T2.'LIG_CDE'))), T2.'MT_ENGAGE' - T3.'MT_LIQ' , T3.'MT_LIQ' , T2.'MT_ENGAGE' , T1.'NU_LIQ' , T2.'QTE_CDEE' , T2.'LIBELLE_LIGNE_CDE' , T1.'LIG_CDE' , T1.'NU_CDE' , T1.'GEST' , T2.'QTE_RECUE' from ('LIG_COMMANDE' T2 LEFT OUTER JOIN ('RECEP_CDE' T3 LEFT OUTER JOIN 'MANDATS_DE_COMMANDES' T1 on T3.'EH'=T1.'EH' and T3.'GEST'=T1.'GEST' and T3.'NU_CDE'=T1.'NU_CDE' and T3.'LIG_CDE'=T1.'LIG_CDE' and T3.'NU_RECEP'=T1.'NU_RECEP' and T3.'NUM_LIQ'=T1.'NU_LIQ') on T2.'EH'=T3.'EH' and T2.'GEST'=T3.'GEST' and T2.'NU_CDE'=T3.'NU_CDE' and T2.'LIG_CDE'=T3.'LIG_CDE') where T1.'NU_CDE'=" & Req & " order by 'LIG_CDE' asc"
ConnecterBase ConnectBD, "\\CLR1DONNEES\0160xxxx\0160*****\My Documents\Mes sources de données\IN01 (Par défaut) COMMANDE.odc", Rs
With Rs
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open ChaineSQL, ConnectBD
Do Until .EOF
Debug.Print .Fields("Champ1") _
& ", " & .Fields("Champ2") _
& ", " & .Fields("Champ3")
.MoveNext
Loop
End With
ConnectBD.Close
Set ConnectBD = Nothing
Set Rs = Nothing
End Sub