I would like to know how can i take a value out of a list box by it's position from column and row.? For example i would like to take value 50 out of column 1 row 9.How can i do that?
Ginorom - I am not sure I understand what you are trying to do. I'll take a couple shots here.
'This would print the value from the 2nd column 11th row in the active form for a listbox named List0. Remember listboxes are 0 based. You can pass variables if you want to change the criteria on the fly
MsgBox Me!List0.Column(1, 10)
This is text from MS Access help.
The next example prints the values of each column for each selected row in the list box, instead of only the values in the bound column.
If you want to play with MS's code just make form named contacts and listbox named Names. Add this code to a pushbutton and it will print all values for the row you have selected
Sub AllSelectedData()
Dim frm As Form, ctl As Control
Dim varItm As Variant, intI As Integer
Set frm = Forms!Contacts
Set ctl = frm!Names
For Each varItm In ctl.ItemsSelected
For intI = 0 To ctl.ColumnCount - 1
Debug.Print ctl.Column(intI, varItm)
Next intI
Debug.Print
Next varItm
End Sub
Ginorom
This code will add the ages of selected items.
Sub Command2_Click()
Dim frm As Form, ctl As Control
Dim varItm As Variant, intI As Integer, ncount As Integer
Set frm = Forms!form1
Set ctl = frm!List3
For Each varItm In ctl.ItemsSelected
ncount = ncount + ctl.Column(1, varItm)
Next varItm
Debug.Print ncount
End Sub
'This adds the age for all items in the list box for your sample listbox
Sub Command2_Click()
Dim intI As Integer, ncount As Integer
For intI = 0 To Me!List3.ListCount - 1
ncount = ncount + Me!List3.Column(1, intI)
Next intI
Debug.Print ncount
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.