0
votes

I have a combo box (myCB) in a form. The user can either select a drop down value or type a value in the box. When the user clicks a button, I want to get the value in the combo box for use in a query.

I am using myCB.Column(0) to grab the value. This works if the user has clicked a selection in the combo box. However, if the user has typed the value, then myCB.Column(0) is null. I have also tried myCB.Text and myCB.Value. Both give null.

How can I grab the combo box value regardless of whether it was selected or typed?

Edited to add properties:
Row Source: "SELECT DISTINCT Item FROM tblItems" (this is set in VBA code, and not in property sheet)
Bound Column: 1
Column Count: 1
Column Widths:
Control Source: ItemName

1
Just referencing combobox without Column(0) works for me. Edit question to show combobox properties: RowSource, BoundColumn, ColumnCount, ColumnWidths. ControlSource.June7
The Value property should give the result you are looking for, and does in my brief testing.Lee Mac
@June7 - Edited as requestedChell
@Lee Mac - The Value property gives the correct result if the value was selected from the drop down, but it gives Null if the value was typed into the combo box.Chell
I tested with bound and unbound combobox. Don't see anything about those settings to cause this issue. Cannot replicate. I was assuming LimitToList property is set to No.June7

1 Answers

0
votes

Figured it out. I was grabbing the combo box value after DoCmd.GoToRecord , "", acNewRec in the OnClick procedure, and the behavior was wonky. Running the value-testing stuff before a new record is accessed yields the correct behavior. Thank you everyone for your help.