List zone VBA/Access

Solved
saanaa Posted messages 16 Status Member -  
 harhor -
Hello everyone

I'm looking for help with VBA/Access
What I want to do is, from a list box, select items by clicking on the chosen item, display them in another list box, and retrieve them.

Thank you all
Configuration: Windows XP Internet Explorer 7.0

8 answers

  1. Milou2211 Posted messages 43 Status Member 11
     
    Good evening,

    Here is part of the response: The selected items from list 1 are transferred to list 2 on the event of your choice
    ---------------1. Empty list 2----
    Private Sub clear_list2()
    Dim x As Integer
    If Me.List2.ListCount > 0 Then
    For x = 1 To Me.List2.ListCount
    Me.List2.RemoveItem (x)
    Next x
    End If
    End Sub

    ---------------2. Populate list 2---------
    Private Sub populate_list2()
    If Me.list1.ItemsSelected.Count > 0 Then
    Me.List2.AddItem Me.list1.Column(1)
    End If
    End Sub

    There are some duplicates checks missing but I hope this helps you.

    Good luck.
    1
    1. harhor
       
      this response is incorrect
      ...see this
      '---Empty the list box
      Do While List.ListCount > 0
      List.RemoveItem (0)
      Loop
      '---
      0
  2. saanaa Posted messages 16 Status Member 1
     
    Hello everyone
    Sorry, I had connection problems so I couldn't respond, but fortunately I solved my problem yesterday
    I have 2 lists:
    in click list1:

    Liste2.AddItem Item:=Liste0, Index:=0
    in click list2:

    Dim a As Integer
    a = Liste2.ListIndex
    If a >= 0 Then Liste2.RemoveItem a '''''' we want to delete the element from the 2nd list

    And to retrieve the data from the 2nd list and search for the corresponding value in a table and store it:

    Dim res, res1 As Recordset
    Dim i As Integer
    Dim didi, REQSQL, REQSQL1, a As String
    ReDim TIdMuf(0 To Liste0.ListCount) As Integer
    For i = 0 To Me.Liste2.ListCount - 1
    a = Me.Liste2.Column(0, i)
    a = "'" & a & "'"
    REQSQL = "SELECT IDMUF,NUMPROMESS,DATEPROMESSE,MATRICULE FROM PROMESSE WHERE MATRICULE=" & a & " "
    Set db = CurrentDb()
    Set res = db.OpenRecordset(REQSQL)
    TIdMuf(i) = res.Fields(0).Value
    Next i

    But now I have another problem: I want to display the result of the query in a table
    I was able to store it in a table but I couldn't display it.
    Thank you
    For TheMan: yes, I have subscribed to VBA/Access this summer lol
    1
  3. saanaa Posted messages 16 Status Member 1
     
    In the click list1:
    List2.AddItem Item:=List0, Index:=0

    actually, the "click list1" refers to the click on the first list named: List0, List2 is the name of the second list.
    1
  4. Archi-dessin Posted messages 281 Registration date   Status Member Last intervention   25
     
    but list0 does not contain any data
    1
  5. Archi-dessin Posted messages 281 Registration date   Status Member Last intervention   25
     
    Liste2.AddItem Item:=List1.List(0)
    1
  6. Archi-dessin Posted messages 281 Registration date   Status Member Last intervention   25
     
    Hello,
    please provide your example to know more.
    0
  7. Archi-dessin Posted messages 281 Registration date   Status Member Last intervention   25
     
    In click list1:

    List2.AddItem Item:=List0, Index:=0
    in click list2:

    in this part, no loading in the LIST1 list, plus List0 does not exist.
    0