首页 > 解决方案 > 是否有一种方法可以根据列表框列之一的条件在列表框中查找值?

问题描述

我有一个列表框,共有 5 列,第 2 列中有电子邮件地址。我有一些代码循环遍历该列并将电子邮件地址添加到电子邮件中的收件人。它工作得很好,但现在我只需要在列表框第 5 列中添加包含特定值的电子邮件地址。

我已经搜索了查找方法,但找不到列表框的任何内容。

这是没有任何查找条件的代码:

strEmailRecipients = ""
For N = 0 To Me.lstContacts.ListCount - 1
    strEmailRecipients = strEmailRecipients & "; " & Me.lstContacts.Column(2, N)
Next N

有什么方法可以修改代码以仅添加第 2 列中满足第 5 列中特定条件的值?

标签: vbams-access

解决方案


我不明白这个问题(也许我错过了一些东西)。

只需使用与已有的相同方法读取列值,使用If.

strEmailRecipients = ""
For N = 0 To Me.lstContacts.ListCount - 1
    If Me.lstContacts.Column(5, N) = "a certain value" Then
        strEmailRecipients = strEmailRecipients & "; " & Me.lstContacts.Column(2, N)
    End If
Next N

推荐阅读