What is the purpose of BOUND COLUMN property of listbox in MS Access?

喜夏-厌秋 提交于 2020-01-04 05:27:52

问题


What is the purpose of BOUND COLUMN property of listbox?


回答1:


The bound column is a number that represents what column from the row source will be used to set the value of the Control Source (if the list box is bound).

Note that you can’t use a column name here. So you don't set the bound column to a column name, but you must use a column number.

Another issue here is that the column number starts at 1 (not zero). Note that OFTEN the 1st column length is set to zero. That allows you to have a list box with something like

select PartNumber, PartDescripton from tblParts

The list box will display the part description, but if you set the bound column = 1, then the listbox will return the PartNumber despite the fact that the listbox is displaying Descriptions (since you set the length of the 1st column = 0. If you set the bound column = 2, then the listbox will return description. Note that you can grab any column value from the list box by using

([lstBox1].Column)

Note that in the above, the column feature is zero based. So, 1 = 2nd column




回答2:


It's the column of the data set that is used to set the value of the listbox. For example, if it's bound to a dataset with the query:

select firstname,lastname,userid from users;

then setting the bound column to userid (3 in the above example) will cause the user ID information to be returned as the listbox value.




回答3:


A bound column is the data that the form is going to save. For instance, if you have a list box or combo box that lists employeeID and employeeName and you set the bound column to 0, the form will save the employee ID number from the selection and insert that value into the corresponding table. You can test which value you are referencing this using this vba:

Private Sub ComboBoxName_AfterUpdate()
   MsgBox ("bound column is: " & Me.ComboBoxName.BoundColumn & ". value is: " & Me.ComboBoxName.Column(0))'change 0 to whatever number column is bound
End Sub

The bound column rule applies even if the first column is hidden on the form. For instance, the user could select "Mike Jones" from the employee list, but the form is going to save Mike Jones' employeeID for data uses (this ID could be stored in a table of sales records, etc.).



来源:https://stackoverflow.com/questions/1360567/what-is-the-purpose-of-bound-column-property-of-listbox-in-ms-access

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