Jaanus
Jaanus

Reputation: 16561

Access combobox value

I have a combobox, and a button, that makes runs a query with the values it gets from combobox, but it does not seem to get the right value. enter image description here

I tried using

[Forms]![Kooli otsing]![Combobox] 

or

[Forms]![Kooli otsing]![Combobox].[Text]

the query did not work, it seems like it does not get the value from combobox. because it worked with normal TextBox.

I ADDED EXPLAINING PICTURE!!!!! enter image description here

ADDED PICTURE OF VBA EDITOR enter image description here

ADDED PICTURE OF ERROR AND NO COMMENT AUTOCOMPLETE enter image description here enter image description here

Upvotes: 2

Views: 18729

Answers (4)

Mark Banford
Mark Banford

Reputation: 43

You can use:

[Forms]![Form1]![Combo1].[Text]

Upvotes: 0

mwolfe02
mwolfe02

Reputation: 24237

Based on the latest comments you posted on your question, you want to use:

[Forms]![Kooli otsing]![Combo19].Column(1)

Here's why. You said you have the following settings for your combobox:

  • column count: 2
  • bound column : 1
  • row source type : table/query
  • row source: SELECT [Haridusasutused].[ID], [Haridusasutused].[Nimetus] FROM Haridusasutused;

Column count of 2 is telling Access to use the first two columns from your rowsource (the only two columns in this case). Bound column is telling access that the default value of the combobox should be the first column of the row source. In this case, that would be [Haridusasutused].[ID]. Often ID columns are autonumber fields.

The reason you were having problems is that [Forms]![Kooli otsing]![Combo19] was returning data from the ID column (most likely a number) not "Elva Gümnaasium". By adding the .Column(1) you are telling Access to choose the data from the second column (.Column is a zero-based array) of the rowsource, ie, "Elva Gümnaasium".

EDIT: Alternatively, you can change the bound column from 1 to 2 and leave the rest alone (ie, you won't need the .Column(1) part at all).

Upvotes: 5

Mikhail G
Mikhail G

Reputation: 309

Have you tried to step through debugger and search for the value through the watch window? For instance put a breakpoint into a button click event, then add [Forms] to the watch window and look into it.

Upvotes: 0

Mark Mooibroek
Mark Mooibroek

Reputation: 7706

This works in my application:

[Forms]![Hour-registration]![mwkselect]

         ^form               ^combobox

Maybe try this to refresh:

Me.Requery
Me.Refresh

Upvotes: 0

Related Questions