2017-02-27 47 views

回答

2

您將需要使用以下步驟的變化:

  1. 形式

  2. 上創建一個列表框填充使用行源列表框中。

  3. 我點擊列表中的一個值,每次去其他選項卡並更改多選屬性擴展

然後我用下面的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打開即時窗口並查看您的勞動成果。

0

就像。 。 。

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 
相關問題