Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing combobox value into SQL query in MS Access

Tags:

sql

vba

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]
like image 446
Alex Gordon Avatar asked Jan 23 '23 01:01

Alex Gordon


1 Answers

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.

like image 75
David-W-Fenton Avatar answered Jan 28 '23 12:01

David-W-Fenton