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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
| Sub Chercher_Click()
Dim reponse ' As String
Dim found ' As String
Dim cell As Range
Dim a As Range
Dim Obj1 As Control, Obj2 As Control, Obj3 As Control, Obj4 As Control, Obj5 As Control, obj6 As Control, obj7 As Control, obj9 As Control
Dim g As Integer, h As Integer, i As Integer, j As Integer, k As Integer, l As Integer, m As Integer
Dim b As Integer
Dim Posg As Long, Posh As Long, Posi As Long, Posj As Long, Posk As Long, Posl As Long, Posm As Long, z As Long, nb As Long
Dim start1 As String
Dim start2 As String
Dim start3 As Currency, start4 As Currency, start5 As Currency
Dim ctrl As Control
Dim CtrlName As String
Dim CtrlTotDu As Currency
Dim Ctrlindex As Integer
Set Collect = New Collection
found = InputBox("n°clt svp")
If Not found = vbNullString Then
reponse = Nbrep(found)
Else: Exit Sub
End If
'========================= boucle Factures=============================
Posi = 12
Posj = 84
Posk = 156
Posl = 228
Posh = 300
b = 40
z = 2
For i = 1 To reponse 'boucle pour la création des textbox
Set Obj1 = Me.Controls.Add("forms.TextBox.1")
Set Obj2 = Me.Controls.Add("forms.TextBox.1")
Set Obj3 = Me.Controls.Add("forms.TextBox.1")
Set Obj4 = Me.Controls.Add("forms.TextBox.1")
Set Obj5 = Me.Controls.Add("forms.TextBox.1")
If start1 = "" And start2 = "" And start3 = 0 And start4 = 0 And start5 = 0 Then
Do While Trim(Worksheets("feuille").Cells(z, 1).Value) <> ""
If Worksheets("feuille").Cells(z, 1).Value Like found Then
start1 = Worksheets("feuille").Cells(z, 8).Value
start2 = Worksheets("feuille").Cells(z, 9).Value
start3 = Worksheets("feuille").Cells(z, 10).Value
start4 = Worksheets("feuille").Cells(z, 11).Value
start5 = Worksheets("feuille").Cells(z, 12).Value
Exit Do
End If
z = z + 1
Loop
Else
Do While Trim(Worksheets("feuille").Cells(z, 1).Value) <> ""
If Worksheets("feuille").Cells(z, 1).Value Like found Then
start1 = Worksheets("feuille").Cells(z + 1, 8).Value
start2 = Worksheets("feuille").Cells(z + 1, 9).Value
start3 = Worksheets("feuille").Cells(z + 1, 10).Value
start4 = Worksheets("feuille").Cells(z + 1, 11).Value & " "
start5 = Worksheets("feuille").Cells(z + 1, 12).Value & " "
z = z + 1
Exit Do
End If
Loop
End If
With Obj1
.Name = "TxtFact" & i
.Object.Value = start1
.Left = Posi
.Top = 70 + b
.Width = 50
.Height = 20
End With
With Obj2
.Name = "TxtDate" & i
.Object.Value = start2
.Left = Posj
.Top = 70 + b
.Width = 60
.Height = 20
End With
With Obj3
.Name = "TxtTotal" & i
.Object.Value = start3
.Left = Posk
.Top = 70 + b
.Width = 50
.Height = 20
End With
'ajout de l'objet dans la classe
Set cl3 = New classe3
Set cl3.TxtTotal = Obj3
Collect.Add cl3
With Obj4
.Name = "TxtAcpte" & i
.Object.Value = start4
.Left = Posl
.Top = 70 + b
.Width = 50
.Height = 20
End With
With Obj5
.Name = "TxtDu" & i
.Object.Value = start5
.Left = Posh
.Top = 70 + b
.Width = 50
.Height = 20
End With
'ajout de l'objet dans la classe
Set cl5 = New classe3
Set cl5.TxtDu = Obj5
Collect.Add cl5
b = b + 40
Next i
'====================== boucle creation prelevement====================
Posm = 374
b = 40
For m = 1 To reponse 'boucle pour la création des TextBox TxtPrel
Set obj7 = Me.Controls.Add("forms.TextBox.1")
With obj7
.Name = "TxtPrel" & m
'.Object.Value = "Prel" & m
.Left = Posm
.Top = 70 + b '* ((i - 1) Mod 5) + 40
.Width = 50
.Height = 20
End With
''ajout de l'objet dans la classe
Set cl7 = New classe3
Set cl7.TxtPrel = obj7
Collect.Add cl7
''If m Mod 5 = 0 Then Posi = Posi + 40
b = b + 40
Next m
'================ boucle creation checkbox===========================
Posg = 450
b = 40
For g = 1 To reponse 'boucle pour la création des CheckBox
Set obj9 = Me.Controls.Add("forms.Checkbox.1")
With obj9
.Name = "ChkCpte" & g
.Left = Posg
.Top = 70 + b
.Width = 15.75
End With
'ajout de l'objet dans la classe
Set cl9 = New classe3
Set cl9.ChkCpte = obj9
Collect.Add cl9
'If m Mod 5 = 0 Then Posi = Posi + 40
b = b + 40
Next g
'===============================================================
For Each ctrl In Me.Controls
CtrlName = ctrl.Name
If InStr(CtrlName, "TxtDu") = 1 Then
CtrlTotDu = CtrlTotDu + ctrl.Text
End If
Next
txttotaldu = CtrlTotDu & " "
End Sub |