1
votes

I have an access form with a bound combobox, using a select query. When the form comes up, it is blank and the user has to select an item by clicking on the drop-down. The bound column is column 1 (ie the second column in the query).

How can I get the combobox to display an initial value (hopefully the first record in the result set)?

2
You are sure the combo is bound? What is the content of the Control Source property?Fionnuala
The Control Source property is blank; Row Source Type is Table/Query and RowSource is "SELECT impTblName, ImpTblDesc FROM tblImpDestTables ORDER BY ImpTblDesc; ". This does retrieve the correct data AND populate the combobox, but then the user has to click to see the items.NiMuSi
Does the combo box have an AfterUpdate event attached? If so, it might be a navigation combo box, and you don't want it to be bound.David-W-Fenton
If the control source is blank, you have an unbound combo. If you wish it to show data already in the database, the control source should be set to the name of the field (column) that contains the data you wish to show. The combo can then be used to read and write data to the database.Fionnuala

2 Answers

3
votes

You can set the Default Value for your unbound combo to one of the values of ImpTblDesc. Then the form should load with the matching combo row selected.

If you want it to always be the first item in the combo's row source, instead of setting a fixed Default Value, you can use this at form load.

Private Sub Form_Load()
    Me.cboNames = Me.cboNames.Column(1, 0)
End Sub

The Column property arguments are column Index, and Row. Both are zero-based.

So that will refer to the second column (your "bound" column) in the first row.

0
votes

For who is searching for this answer? I used

Private Sub Form_Load()
  Me.cboNames.Value = Clng(Me.cboNames.Column(0, 0))
End Sub