Link to home
Start Free TrialLog in
Avatar of CipherIS
CipherISFlag for United States of America

asked on

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?

Thanks
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

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?
Avatar of CipherIS

ASKER

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
            rs.MoveNext
            i = i + 1
        Loop
    End If
    
    rs.Close

End Sub

Open in new window

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 ?
I figured it out.  Thanks for the help.
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
ASKER CERTIFIED SOLUTION
Avatar of CipherIS
CipherIS
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
Resolved the issue