Passing combobox value to MS ACCESS sql query

I have a combobox on the form

I want combobox text to be passed to the request.

my request:

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

the name of the form enters data, and the name combobox - combocup. should i do:

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

or

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

??

+4
source share
4 answers

You must use [Forms]! [Enter the data]! [comboCup].

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

The .Value property is redundant because it is the default property for all Access controls, so these are two equivalents:

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

(note also that properties, such as .Text and .Value, are separated by the dot operator, not by the hit that defines the collections)

One issue that may be troubling is that you want to use the value of the combo box in the SELECT statement of an APPEND request. In this case, you will be asked to declare the combo box as a parameter in the saved query. If you do not, this may lead to the row not being inserted, whereas if you declare a parameter, it will solve Null, which is the value in the corresponding combo box.

+6
source

None. Text is only available if the control has focus. The value of comboCup is a related column. Make sure your query looks for this value, otherwise you will need to reference the property of the combo column.

+2
source
 Dim comboBoxText As String comboBoxText = Me.YourComboboxName.Column(1) 

Note: Combobox column is 1 based array

+1
source

If you work in the Form module, you can do something like this (pseudo-code only):

 Event comboCup_afterUpdate() strCup = Me!comboCup strSQL = "SELECT ... etc ... ='" & strCup & "'" End Sub 

If another module still uses variables, as shown above; in this case, however, your syntax for identifying a field in a form requires a lot of work. I can tell you more about this if it all makes sense so far.

0
source

Source: https://habr.com/ru/post/1309922/


All Articles