访问VBA:查找基于非绑定列组合框项目 [英] Access VBA: Find item in combo box based on non-bound column
问题描述
我有一个访问的形式重新presenting一键于─code映射一个两列的组合框。组合框的第一列是绑定列(即,该列使用时 MyComboBox.Value
被调用)。
I have a two-column combo box on an Access form representing a key-to-code mapping. The first column of the combo box is the 'bound column' (ie, the column used when MyComboBox.Value
is called).
我需要的基础上,在第二列中的值来动态设置值
我的组合框。对于例如,如果我的组合框的来源是:
I need to dynamically set the Value
of my combo box based on a value found in the second column. For eg, if my combo box source is:
Value | Code
===============
A1 | ABCD
A2 | EFGH
A3 | IJKL
我可以设置组合框的值,简单地用 ComboBox.Value =A2
,但我会怎么做同样采用第二列? ComboBox.Value =EFGH
显然是无效的。本质上寻找逻辑沿 ComboBox.Value = ComboBox.ValueWhereSecondColumnEquals(EFGH)
I can set the value of the combo box simply with ComboBox.Value = "A2"
, but how would I do the same using the second column? ComboBox.Value = "EFGH"
obviously isn't valid. Essentially looking for logic along the lines of ComboBox.Value = ComboBox.ValueWhereSecondColumnEquals("EFGH")
推荐答案
和假设它不是基于表/查询:
And assuming it's not based on a table/query:
Dim i As Integer
For i = 0 To ComboBox.ListCount-1
If ComboBox.Column(1, i) = "EFGH" Then
ComboBox.Value = ComboBox.ItemData(i)
Exit For
End If
Next i
这篇关于访问VBA:查找基于非绑定列组合框项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!