Bonjour,
Je dispose d'un base de donnée avec une table "prestation" qui contient 4 champs:
Le nom de la prestation (libelle_prestation), les prix min, moy & max de la prestation (respectivement min_ht, moy_ht et max_ht)
Dans un premier temps une datalist (datalist1) récupere le champs libelle_prestation, lorsque l'utilisateur clique sur le bouton "ajouter" cella l'ajoute sur une listbox (list1).
Une fois que l'on a choisi les prestations voulues, pour chaque prestation son nom apparait dans une textbox ainsi que ces 3 prix associés (checkbox). Mais je n'arrive pas a faire apparaitre les bon prix dans les check box.
Comme je permets le choix de 6 prestations max, il y a donc 18 checkbox associées (1 min, 1 moy et 1 max pour chaque prestation)
Voici le code :
Option Explicit
Dim MaDb As String
Private Sub cmdAdd_Click()
List1.AddItem DataList1.Text
cmdCalc.Refresh
End Sub
Private Sub cmdCalc_Click()
Dim i As Integer
Dim j As Integer
Dim k As Integer
lblMin.Visible = True
lblMoy.Visible = True
lblMax.Visible = True
lblTitre2.Visible = True
Select Case List1.ListCount
Case "1"
Text1(0).Visible = True
For j = 0 To 2
Check1(j).Visible = True
Next j
Case "2"
For i = 0 To 1
Text1(i).Visible = True
Next i
For j = 0 To 5
Check1(j).Visible = True
Next j
Case "3"
For i = 0 To 2
Text1(i).Visible = True
Next i
For j = 0 To 8
Check1(j).Visible = True
Next j
Case "4"
For i = 0 To 3
Text1(i).Visible = True
Next i
For j = 0 To 11
Check1(j).Visible = True
Next j
Case "5"
For i = 0 To 4
Text1(i).Visible = True
Next i
For j = 0 To 14
Check1(j).Visible = True
Next j
Case "6"
For i = 0 To 5
Text1(i).Visible = True
Next i
For j = 0 To 17
Check1(j).Visible = True
Next j
End Select
For i = 0 To 5
Text1(i).Text = List1.List(i)
Next i
End Sub
Private Sub cmdCalcFin_Click()
Dim j As Integer
For j = 0 To (3 * List1.ListCount - 1)
If Check1(j).Value = 1 Then
Text2.Text = Val(Text2.Text) + Val(Check1(j).Caption)
End If
'cmdCalcFin.Refresh
Next j
If Text2 <> "" Then
Text3.Text = Text2.Text * 0.804
'cmdCalcFin.Refresh
End If
End Sub
Private Sub CmdQuit_Click()
Unload Me
End Sub
Private Sub cmdRemove_Click()
Dim i As Variant
For i = List1.ListCount - 1 To 0 Step -1
If List1.Selected(i) = True Then
List1.RemoveItem i
Text1(i).Visible = False
Check1(3 * i).Visible = False
Check1(3 * i + 1).Visible = False
Check1(3 * i + 2).Visible = False
End If
Next i
cmdCalc.Refresh
End Sub
Private Sub Form_Load()
Dim i As Integer
Dim j As Integer
lblMin.Visible = False
lblMoy.Visible = False
lblMax.Visible = False
lblTitre2.Visible = False
For i = 0 To 5
Text1(i).Visible = False
Next i
For j = 0 To 17
Check1(j).Visible = False
Next j
MaDb = App.Path & ".\FiiTCompta.mdb"
With Adodc1
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & MaDb & ";Persist Security Info=False"
.RecordSource = "SELECT * FROM Prestation ;"
End With
Adodc1.Refresh
Set DataList1.DataSource = Adodc1
Set DataList1.RowSource = Adodc1
DataList1.DataField = Adodc1.Recordset.Fields(0).Name
DataList1.ListField = Adodc1.Recordset.Fields(0).Name
Check1(0).Caption = Adodc1.Recordset.Fields(1).Value 'correspond au prix min
Check1(1).Caption = Adodc1.Recordset.Fields(2).Value 'correspond au prix moy
' Check1(2).Caption = Adodc1.Recordset.Fields(3).Value 'correspond au prix max
End Sub
Ma table est tte bete, avec en champs1 les libelle_prestation, champs2 le prix mix, champs3 le prix moy & champs4 le prix max.
Avec Check1(0).Caption = Adodc1.Recordset.Fields(1).Value je n'obtiens que le premier élement du champs min. J'aimerais pouvoir choisir la ligne correspondante à la bonne prestation. J'ai vu qu'avec getrows je pourrais m'en tirer, mais ni mes recherches sur google, ni msdn ne m'ont permis de comprends comment m'en servir.
Mon idée c'est de faire une boucle ou je compare le contenu du text1 (0) (celui qui récupere la premiere prestation choisie) avec les noms des prestations, pour ensuite mettre les prix corespondants dans les 3 checkbox.
J'ai tenté de commencer avec ca:
With Adodc1.Recordset
.Find "libelle_prestation= " & Text1(0).Text & ""
mais je ne sais pas comment continuer
Sinon je pensais mettre le contenu de ma table dans un tableau a 2 dimensions. Je pourrais y naviguer plus facilement. Mais je m'y perds parmis les array etc.... (je débute)
Désolé pour ce gros pavé, mais je suis dans l'impasse et sans prendre le temps d'expliquer mon prob je doute que l'on puisse m'aider.
Merci