Programatically Select a Row in MS Access Combobox
Today, I was working on our web team documentation system, which has a MS Access front end with a SQL Server 2005 backend.
I needed to programatically select a row in a combobox and have done so many times; however, I could not remember. As a result, I decided to post the method I wrote here for future reference.
I needed to programatically select a row in a combobox and have done so many times; however, I could not remember. As a result, I decided to post the method I wrote here for future reference.
Vivian
SelectComboboxRow Me.cboStoredProcID, StoredProcID_Arg, 0, False
Private Sub SelectComboboxRow(MyCombobox As Combobox,
MyValueRow As Long,
MyColumn As Long,
ShowDebug As Boolean)'set to first column
'Me.Combobox.DefaultValue = Me.Combobox.Column(0, 0)
For intCounter = 0 To MyCombobox.ListCount - 1
If MyCombobox.ItemData(intCounter) = MyValueRow Then
If (ShowDebug) Then
MsgBox "Found Value of Column " & MyCombobox.Column(MyColumn, intCounter)
MsgBox "Found The Value of Item" & MyCombobox.ItemData(intCounter)
End If
MyCombobox.Selected(intCounter) = MyValueRow 'nothing
MyCombobox.Value = MyValueRow
End If
NextEnd Sub


Comments