Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help getting data from a listbox

Status
Not open for further replies.

cal555

Programmer
May 5, 2006
71
0
0
US
hi,
I tring to get the items that a user selected in in a list box. These are hard coded values in the box(they do not want to use a table). They want them to be able to select more than one itme. So I need to be able to grab and store the text in an array or variables. I have this code but so far it does not work. When it gets to to the item it showsit as having a NUll value, and passes by it. It also goes forever and I would have expected the auto increment.
Can someone please tell me what I am doing wrong.
Thank you

Here is my code:

Dim st As String
Dim a() As String

Do While listPOS.ListCount
ReDim a(listPOS.ListCount)
If listPOS.ListIndex >= 0 Then
If listPOS.Value <> Null Then
a(listPOS.ListCount) = listPOS.Value
txtCONTRACT_NAME = a(listPOS.ListCount)
End If
End If
 
for i = 0 to listpos.listcount-1
msgbox listpos.list(i)
next

demonstrates a/ the way to procede; could be you will not require an array.

HTH Hugh
 



Hi,

Tak a look at the SELECTED property of the ListBox Object.

Skip,
[sub]
[glasses] [red][/red]
[tongue][/sub]
 
Thanks for your help, but listpos.list(i)
does not seem to be allowed and I have tryed looking at selected properties and nothing seems to be working there either. But I think there has to be a way to do this is n't there?
 
If by chance you use an Access ListBox then have a look at the ItemsSelected collection.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Following on from Skip I should have given you a little more;

for i = 0 to listpos.listcount-1
If listpos.Selected(i) Then
msgbox listpos.list(i)
End if
next

You say listpos.list(i) is not working;

1) Is this a ListBox created from the Control Toolbox toolbar or the Forms toolbar.

2) Does the ListBox occur on a UserForm or over a Sheet

Hugh
 
Thnk you everyone, I did get it ot work.
Thank you
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top