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.

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
    Next
End Sub
Vivian
 

What did you think of this article?




Trackbacks
  • No trackbacks exist for this post.
Comments
  • No comments exist for this post.
Leave a comment

Submitted comments are subject to moderation before being displayed.

 Name (required)

 Email (will not be published) (required)

Your comment is 0 characters limited to 3000 characters.