I haven't a clue as to what you mean by "OrderNumber is a control of OrderSummary"--you seem to
be implying that your listbox, named OrderSummary, somehow contains controls within it (?). I
think what you want is to obtain the value selected in the listbox. You can use code similar to
the following to select the data in the BOUND column. In this example, the name of the listbox
is lstReports.
Private Sub lstReports_DblClick(Cancel As Integer)
Dim varItem As Variant
For Each varItem In Me.lstReports.ItemsSelected
Debug.Print Me.lstReports.ItemData(varItem)
Next varItem
End Sub
On the other hand, if your listbox displays two or more columns, and you want to obtain the value
in a column that is not specified as the bound column, for the row selected, use the .Column
property instead. Here, the columns are "zero-based" (ie. column 0 is the first column, column 1
is the second column, etc.):
Private Sub lstReports_DblClick(Cancel As Integer)
Dim varItem As Variant
For Each varItem In Me.lstReports.ItemsSelected
Debug.Print Me.lstReports.Column(1, varItem)
Next varItem
End Sub
Tom
___________________________________________
I have a list box within a main form. After a row is selected in the list box, I want to print
and test a control in the lsit box. The following is my code but I always got error message.
Please advise how to refer to a control in a list box.
Debug.Print Me!OrderSummary.ItemsSelected.OrderNumber
OrderSummary is the name of the list box
OrderNumber is a control of OrderSummary