1

i have access 2007 and i want to update a text field [eng] using a list box [List191] which contains 3 values value1,value2,value3

i want when i click on this list and select one or two values i get this values as text separated with (,) in that text field

something like :

Private Sub List191_Click()
Form_tbltest.[eng].Value = Form_tbltest.[eng].Value &","& Form_tbltest.List191.value 
End Sub

this code is not working with me , any suggestions ???

user1921704
  • 179
  • 3
  • 4
  • 15

1 Answers1

1

If you have a multi-select list box, look at the Access help topics for ListBox.ItemsSelected Property and ListBox.ItemData Property.

In this example, I chose the list box's After Update event for the code. I named my text box txtEng. The code loops through the list box's ItemsSelected collection, and adds the ItemData value for each to a string variable, strEng. After the loop, the leading comma is discarded when the length of that string is > 0. Finally the string's value is assigned to the text box.

Private Sub List191_AfterUpdate()
    Dim strEng As String
    Dim varItem As Variant

    For Each varItem In Me.List191.ItemsSelected
        strEng = strEng & "," & Me.List191.ItemData(varItem)
    Next
    If Len(strEng) > 0 Then
        strEng = Mid(strEng, 2) ' discard leading comma
    End If
    Me.txtEng = strEng
End Sub
HansUp
  • 95,961
  • 11
  • 77
  • 135