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
| Option Compare Database
Option Explicit
Private Sub Form_Load()
InitializeList
End Sub
Private Sub InitializeList()
Const fmLIST_STYLE_OPTION As Integer = 1
Const fmMULTI_SELECT_SINGLE As Integer = 0
Const fmMULTI_SELECT_MULTI As Integer = 1
Const fmMULTI_SELECT_EXTENDED As Integer = 2
Dim oRS As DAO.Recordset
Dim blnIsAvailable() As Boolean
Dim R As Integer
Dim I As Integer
Dim oCtl As Object
Dim SQL As String
SQL = "SELECT [Réf produit], [Nom du produit], [Prix unitaire], Indisponible "
SQL = SQL & " FROM Produits WHERE (((Produits.[Niveau de réapprovisionnement])>10" & _
" AND (Produits.[Niveau de réapprovisionnement])<16));"
Set oRS = CurrentDb.OpenRecordset(SQL, 2)
Set oCtl = lstCriteria.Object
vntDataArray = oRS.GetRows
With oCtl
.Clear
.ColumnCount = 3
.ListStyle = fmLIST_STYLE_OPTION
.MultiSelect = fmMULTI_SELECT_MULTI
.BoundColumn = 2 'ID du produit
End With
R = -1
With oRS
If Not .EOF Then
.MoveFirst
Do While Not .EOF
R = R + 1
ReDim Preserve blnIsAvailable(0 To R)
oCtl.AddItem " " & .Fields("Réf produit")
oCtl.List(oCtl.ListCount - 1, 1) = .Fields("Nom du produit")
oCtl.List(oCtl.ListCount - 1, 2) = .Fields("Prix unitaire")
If .Fields("Indisponible") = True Then blnIsAvailable(R) = True
.MoveNext
Loop
.Close
For I = 0 To oCtl.ListCount - 1
oCtl.Selected(I) = blnIsAvailable(I)
Next
End If
End With
Set oCtl = Nothing
Set oRS = Nothing
End Sub |