Access combobox value

回眸只為那壹抹淺笑 提交于 2020-01-15 08:12:51

问题


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


回答1:


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).




回答2:


This works in my application:

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

         ^form               ^combobox

Maybe try this to refresh:

Me.Requery
Me.Refresh



回答3:


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.




回答4:


You can use:

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


来源:https://stackoverflow.com/questions/5593372/access-combobox-value

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!