Skip to content
Advertisement

Passing combobox value into SQL query in MS Access

I have a combobox in a form, and I want the text of the combobox to be passed into a query.

My query is:

select..from..where something=[Forms]![Enter Data]![comboCup]

The form’s name is Enter Data and the combobox’s name is comboCup. Should i do this:

[Forms]![Enter Data]![comboCup]![text]

or this?

[Forms]![Enter Data]![comboCup]![value]

Advertisement

Answer

You should use [Forms]![Enter Data]![comboCup].

As @Remou has said, the .Text property of an Access control is available only when the control has the focus.

The .Value property is redundant, as it’s the default property of all Access controls, so these two are equivalent:

  [Forms]![Enter Data]![comboCup]
  [Forms]![Enter Data]![comboCup].Value

(note also that properties like .Text and .Value are separated by the dot operator and not the bang, which delineates collections)

One issue that can be of concern is if you want to use the value of the combo box in the SELECT statement of an APPEND query. In that case, you would be advised to declare the combo box as a parameter in your saved query. If you do not, it can cause the row to not be inserted, whereas if you declare the parameter, it will resolve to the Null that is the value in the referenced combo box.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement