Access 2007年 - 通过值在列表框中VBA骑自行车吗? [英] Access 2007 - cycling through values in a list box VBA?

查看:115
本文介绍了Access 2007年 - 通过值在列表框中VBA骑自行车吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个列表框,数据的基于用户选择不同的设置填充。

So i have a list box that populates with different sets of data based on user selections.

我如何循环任何给定的值可能会在列表框中?这是一个对于每个语句,还是什么?

How can I cycle through any given values that may be in the list box? Is this a For Each statement, or what?

请帮忙 谢谢 贾斯汀

推荐答案

您可以做你一个循环检查在列表框中的每一行,做的无论的与被选择的行。在这个例子中,我显示来自在 lstLocations所选项目的列表框中的第二列。 (列编号从0开始。)

You can do you a For loop to examine each row in the listbox, and do whatever with the rows which are selected. In this example, I display the second column from selected items in the lstLocations listbox. (Column numbering starts with zero.)

Private Sub cmdShowSelections_Click()
    Dim lngRow As Long
    Dim strMsg As String

    With Me.lstLocations
        For lngRow = 0 To .ListCount - 1
            If .Selected(lngRow) Then
                strMsg = strMsg & ", " & .Column(1, lngRow)
            End If
        Next lngRow
    End With

    ' strip off leading comma and space
    If Len(strMsg) > 2 Then
        strMsg = Mid(strMsg, 3)
    End If
    MsgBox strMsg
End Sub

请注意我假设你想从列表框中选定的项目。如果你想要的所有的项目,选择或没有,你可以使用 .ItemData 作为@DavidRelihan的建议。然而,在这种情况下,你可以从列表框中 .RowSource ,而不是让他们。

Note I assumed you want the selected items from the list box. If you want all items, selected or not, you could use .ItemData as @DavidRelihan suggested. However, in that case, you could get them from the listbox .RowSource instead.

这篇关于Access 2007年 - 通过值在列表框中VBA骑自行车吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆