[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 40
  • Last Modified:

MS Access 2007 - Programatically select value in combobox

I am populating a form and I need to programatically select a value in a combobox.

I tried me.mycombobox.value = i

Its not working.

Any idea how to do this?

  • 5
  • 2
1 Solution
Rey Obrero (Capricorn1)Commented:
what is the rowsource of the combo box?

post the rowsource of your combo box.

is your form bound to a table or query or unbound?
CipherISAuthor Commented:
Here is how the combobox is being populated.

Private Sub GetLocations()

    Dim db As Database
    Dim rs As Recordset
    Dim i As Integer
    i = 0
    sql = "SELECT LocationID, LocationType, LocationName, ProjectID "
    sql = sql & "FROM Location "
    sql = sql & "WHERE ProjectID = " & Me.cboProjectID.Column(0) & " "

    Set db = CurrentDb
    Set rs = db.OpenRecordset(sql)

    Me.cboLocation.RowSource = ""

    If Not rs.EOF Then
        Me.cboLocation.Locked = False
        Do Until rs.EOF
            Me.cboLocation.AddItem Item:=rs![LocationID] & ";" & rs![LocationName] & ";" & rs![LocationType], Index:=i
            i = i + 1
    End If

End Sub

Open in new window

Rey Obrero (Capricorn1)Commented:
what about your form, can you provide a description about your form?

can you give more explanation on

< i need to  programatically select a value in a combobox. >

based on what?, which item in the combo box do you want to be selected programmatically ?
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

CipherISAuthor Commented:
I figured it out.  Thanks for the help.
CipherISAuthor Commented:
I've requested that this question be closed as follows:

Accepted answer: 0 points for CipherIS's comment #a39158637

for the following reason:

figured it out
CipherISAuthor Commented:
me.mycombobox.value = i was the solution.  There was an issue with the combobox.
CipherISAuthor Commented:
Resolved the issue

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now