Link to home
Start Free TrialLog in
Avatar of Agent909
Agent909

asked on

How to programatically change ComboBox selection

After a record is saved in my application, a combobox is refilled to include the new item.  How do I programatically move the position of the combobox to the new record?

Thanks!
Avatar of kaufmed
kaufmed
Flag of United States of America image

Assuming you are adding to the end of the list:
Me.comboBox1.SelectedIndex = Me.comboBox1.Items.Count - 1

Open in new window

Avatar of Agent909
Agent909

ASKER

Actually, the list is sorted first, so it won't be the last item.
The values in the combobox are:

Description - what's shown
RecordID - the index
I discovered that the values in my combobox are objects.  Here's some code I used to test this.  So, there's got to be a way to access the recordID to set the combobox's SelectedValue.  

        Dim obj As WebPage
        For Each obj In cboSites.Items()
            ' this does work
            Debug.Print(obj.SiteDescription)
            ' this will hang
            If obj.SiteDescription = "Google" Then
                cboSites.SelectedValue = obj.RecordID
            End If
        Next

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Zhaolai
Zhaolai
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Your code is sending me in the right direction.  Thank you!