VBA access: finding an item in a column-based combo box based on a column without binding

I have a two-column combo box in an Access form representing a key-code mapping. The first column of the combo box is the “linked column” (i.e., the column used in the call MyComboBox.Value).

I need to dynamically set Valuemy combo box based on the value found in the second column. For example, if my source is with a list:

Value | Code
===============
 A1    | ABCD
 A2    | EFGH
 A3    | IJKL

I can set the value of the combo box just with ComboBox.Value = "A2", but how would I do the same with the second column? ComboBox.Value = "EFGH"obviously wrong. Essentially, searching for logic along linesComboBox.Value = ComboBox.ValueWhereSecondColumnEquals("EFGH")

+5
source share
3 answers

/:

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
+5

, , DLookUp :

 ComboBox.Value = Dlookup("Value","Table","Code='" & sCode & "'")
+3

, , - , .BoundColumn , cboX = cboY. , .

0

All Articles