Public old_color, old_sel
Public posrow%
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim Cn As ADODB.Connection
Dim Rs As ADODB.Recordset
'On Error GoTo DisplayErrorInfo
Set Cn = New ADODB.Connection
Cn.ConnectionString = "driver={SQL Server};" & _
"server=GI-ERP;uid=Int;pwd=!Huttopia!;database=" & Worksheets("Param").Cells(1, 2).Value
Cn.Open
'On Error GoTo DisplayErrorClient
Set Rs = New ADODB.Recordset
Rs.ActiveConnection = Cn
Worksheets("Données").Unprotect "Gitotel2019" 'ou mdp est ton mot de passe
' Nettoyage
NbLig = Worksheets("Données").Range("A" & Rows.Count).End(xlUp).Row
Worksheets("Données").Range("A2:C" & NbLig + 1).ClearContents
Requete = "SELECT S.DPKTCODART, S.DPKTCOMART, S.DPKTNUMLOT FROM STDEPLOT AS S, ARTICLE AS A WHERE S.DPKTCODART = '" & Target.Value & "' AND S.DPKTCOMART = '" & Cells(Target.Row, 5).Value & "' AND S.DPKTCODART = A.ARKTCODART AND S.DPKTCOMART = A.ARKTCOMART AND A.ARCTFATN = '31'"
Rs.Open Requete
If Not IsEmpty(Target.Value) Then
If Not Rs.EOF Then
Lig = 1
Do While Not Rs.EOF
Lig = Lig + 1
Worksheets("Données").Cells(Lig, 1) = Trim(Rs.Fields(0)) ' Num série
Worksheets("Données").Range("A" & Lig).HorizontalAlignment = xlCenter
Worksheets("Données").Cells(Lig, 2) = Trim(Rs.Fields(1)) ' code comp
Worksheets("Données").Range("B" & Lig).HorizontalAlignment = xlCenter
Worksheets("Données").Cells(Lig, 3) = Trim(Rs.Fields(2)) ' CC composant
Worksheets("Données").Range("C" & Lig).HorizontalAlignment = xlCenter
Rs.MoveNext
Loop
Rs.Close
posrow = Target.Row
ListePF.Show
End If
End If
Cn.Close
Worksheets("Données").Protect "Gitotel2019", AllowFiltering:=True
'Etiquettes de gestion des erreurs
GoTo DisplayEnd
DisplayErrorClient:
MsgBox ("La requête a échoué, contactez votre service de développement")
GoTo DisplayEnd
DisplayErrorInfo:
MsgBox ("Impossible de se connecter à la base de données")
GoTo DisplayEnd
DisplayEnd:
End Sub