1
如何在列表框中選擇多個項目,然後參考我選擇的項目?請參閱ms-access中列表框中的多個選定項目
如何在列表框中選擇多個項目,然後參考我選擇的項目?請參閱ms-access中列表框中的多個選定項目
您將需要使用以下步驟的變化:
形式
上創建一個列表框填充使用行源列表框中。
然後我用下面的VBA
Option Compare Database
Private Item_IDs as string
Private Sub List_item_id_Click()
Dim i As Integer, count As Integer
Dim Item_IDs As String
count = 1
For i = 0 To Me.List_item_id.ListCount - 1
If Me.List_item_id.Selected(i) = True Then
Item_IDs = Item_IDs & ", " & Me.List_item_id.ItemData(i)
count = count + 1
End If
Next i
Item_IDs = Mid(Item_IDs, 3)
Debug.Print Item_IDs
End Sub
現在,它會返回我選擇的東西的逗號分隔值字符串(Item_IDs)。在VBA窗口中使用CTRL + G打開即時窗口並查看您的勞動成果。
就像。 。 。
Private Sub OKButton_Click()
Dim Msg As String
Dim i As Integer
Msg = "You selected" & vbNewLine
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) Then
Msg = Msg & ListBox1.List(i) & vbNewLine
End If
Next i
MsgBox Msg
Unload UserForm1
End Sub