You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Access VBA如何获取列表框(ListBox)选中项实际值而非索引

Access VBA 列表框(ListBox)选中项取值方法

单选项列表框取值

  • 若需要获取绑定列的实际值,直接调用控件的Value属性即可:
Dim selectedValue As Variant
' 将ListBox1替换为你实际的列表框控件名称
selectedValue = Me.ListBox1.Value
  • 若需要获取非绑定列的实际值,调用Column属性,传入你已经拿到的0起始选中索引即可:
Dim selectedIndex As Integer
Dim targetColValue As Variant
' 你已获取到的0起始选中行索引
selectedIndex = Me.ListBox1.ListIndex
' 示例获取第2列的值,列索引从0开始计数,替换1为你需要的列索引即可
targetColValue = Me.ListBox1.Column(1, selectedIndex)

多选项列表框取值

如果列表框开启了允许多选,遍历ItemsSelected集合获取所有选中行的实际值:

Dim selectItem As Variant
Dim result As String ' 也可改用数组存储多个选中值

For Each selectItem In Me.ListBox1.ItemsSelected
    ' 取选中行绑定列的值
    result = result & ";" & Me.ListBox1.ItemData(selectItem)
    ' 取选中行指定列的值,替换1为对应列索引即可
    ' result = result & ";" & Me.ListBox1.Column(1, selectItem)
Next selectItem
' 移除开头多余的分隔符
If Len(result) > 0 Then result = Mid(result, 2)

注意事项

  • Column属性的第一个参数为列索引,从0开始计数,和列表框的列排列顺序一一对应
  • 行来源为「值列表」的列表框,上述方法同样适用,无需额外调整

内容的提问来源于stack exchange,提问作者Riccardo G

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.27 00:15:08