vba 如何设置 ms-access 组合框选定索引

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8283877/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 12:13:41  来源:igfitidea点击:

how to set ms-access combo box selected index

ms-accessvbams-access-2007access-vba

提问by shamim

In my ms access project I need to refresh my combobox.I use bellow syntax to select the first item .

在我的 ms access 项目中,我需要刷新我的组合框。我使用波纹管语法来选择第一项。

Application.CommandBars("MainMenu").Controls("Country").SelectedValue = "US"

After use the above syntax show error”Object does not support this property or method” enter image description hereNeed help to set the combo box selected item

使用以上语法后显示错误“对象不支持此属性或方法” 在此处输入图片说明需要帮助设置组合框选中项

If have any query plz ask.Thanks in advance

如果有任何疑问请询问。提前致谢

回答by mahmoud

 Me.fromDate = Me.fromDate.ItemData(0)    'Get first item

 Me.toDate = Me.toDate.ItemData(Me.toDate.ListCount - 1) 'Get last item 

回答by Olivier Jacot-Descombes

You can also set the desired selected value directly:

您也可以直接设置所需的选定值:

Me!cboTest = "US"

回答by shamim

Hope Bellow syntax solve problem

希望 Bellow 语法解决问题

Just use the combo.ListIndex=ComboBoxIndex

只需使用 combo.ListIndex=ComboBoxIndex

回答by user3164282

In Access 2013 ListIndex is readonly. You can change the value of the combobox as suggested above. When you do so, the ListIndex is modified by Access but it won't point to the row you used. I've not found any information on how to select a row and have the ListIndex point to that row after selection. The only solution I can come up with is to keep static variables around that I maintain to keep track of what is really selected.

在 Access 2013 中,ListIndex 是只读的。您可以按照上面的建议更改组合框的值。当您这样做时,ListIndex 会被 Access 修改,但它不会指向您使用的行。我没有找到任何关于如何选择一行并在选择后让 ListIndex 指向该行的信息。我能想出的唯一解决方案是保留我维护的静态变量,以跟踪真正选择的内容。