Reputation: 16561
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.
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!!!!!
ADDED PICTURE OF VBA EDITOR
ADDED PICTURE OF ERROR AND NO COMMENT AUTOCOMPLETE
Upvotes: 2
Views: 18729
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:
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
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
Reputation: 7706
This works in my application:
[Forms]![Hour-registration]![mwkselect]
^form ^combobox
Maybe try this to refresh:
Me.Requery
Me.Refresh
Upvotes: 0