I'm new to Access so this might be a simple question.
I have a form in Access 2013. There is a subform displaying a table from an SQL server, like so.
Company Product
-----------------
CompanyA Product1
CompanyA Product2
CompanyB Product1
CompanyB Product2
Using ListIndex in a list box, I can display the index of any row I click on. For example if I click on the second row (CompanyA, Product2) the list box shows a ListIndex of 1. If I click on the third row the ListIndex is 2.
How do I get a list box to display the value of a column instead of the ListIndex?
What I am trying to do is that, when I click on a row in the subform, I'd like to display each column value for that row in its own list box.
However, I cannot seem to use ListIndex as a variable in a larger function. I've attempted the following:
Is there a different property I should be using? Am I missing something in the properties I tried?
答案 0 :(得分:1)
似乎与术语有点混淆。您的List3
是一个列表框,而不是子表单。
字段Company
和Product
看起来像文本框,但如果第一个字段具有控件来源=[List3].[ListIndex]
,并显示文本而不是数字,则它似乎是列表框的高度=一行。
我建议对Company
和Product
使用文本框,并使用以下控件来源:
=[List3]
表示绑定列。或者,为了保持一致性:=[List3].Column(0)
=[List3].Column(1)
为第二列。
当您单击列表框中的项目时,这些文本框会自动更新。
答案 1 :(得分:0)
To get the value of a listbox, and if you allow multi-select, use the following example:
For Each varItem In Me.lstHierarchy.ItemsSelected ' Loop through the items selected (if multi-select allowed)
strPrint = ""
For i = 0 To iCols ' Loop thru each column in a row
strPrint = strPrint & "|" & Me.lstHierarchy.Column(i, varItem)
Next i
Debug.Print "Selected Value: " & strPrint ' Display the row; columns are delimited with '|'
Next