Access 2007 Using the ID value from a list box in VBA/SQL statement

女生的网名这么多〃 提交于 2019-12-24 22:27:18

问题


Guys...if I want to run a button click event that takes a list box and uses the ID field that is in the listbox in a SQL statement in VB, then is it

me.MyListbox.selected

or

me.MyListbox.value

to get that value? for some reason I have tried both and neither seem to be working. .value returns an empty value, and .selected generates an error stating the argument is not valid.

thanks justin


回答1:


If the ID is the bound column and the listbox is not multiselect, you can use just the name of the listbox without any other qualifier. If the ID is not the bound column, then use the column property to get the value : MyListBox.Column(n) where n is the column number starting from zero.

For multiselect listboxes, you need to iterate through the selected items to get a list to use with SQL.

If you are using the query design window or a control on a form or report, you cannot use Me, you must either use the full reference (Forms!Formname!ControlName) or for a control on the same form, just the name of the listbox.



来源:https://stackoverflow.com/questions/3423442/access-2007-using-the-id-value-from-a-list-box-in-vba-sql-statement

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