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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

listbox help

Status
Not open for further replies.

zyphac

Technical User
Mar 12, 2003
47
US
ok here is the code: then I tell the problem
Private Sub contractdata_AfterUpdate()

Dim lst As ListBox
Dim intI As Integer, intJ As Integer

Set lst = Me!contractdata

' Print value of each column for each row.
For intI = 0 To lst.ListCount - 1
For intJ = 0 To lst.ColumnCount - 1
Me!date = [contractdata].Column(0)
Me!con = [contractdata].Column(1)
Me!sold = [contractdata].Column(2)
Me!ship = [contractdata].Column(3)

Next intJ
Next intI
End Sub
ok I have a listbox name contract data, ,and several text boxes. The listbox is set to multi select, and it puts my data in the respective text box, per code. It works but when I multi select it just changes the first line, and doesn't keep listing them in my text boxes. What am I doing wrong?
Thanks
zypha
 
for one you only set one value at a time in the textboxes so you will only see the last or the first

but try this

Dim varItm As Variant

Text3 = ""
For Each varItm In List1.ItemsSelected
me!date = me!date & " " & List1.Column(0, varItm)
...
Next varItm
Christiaan Baes
Belgium
"What a wonderfull world" - Louis armstrong
 
Well I tried it and it worked but every time I deselected it still put the data in the text box, the lest box went wild, also should I put the code behind the afterupdate?
thanks zypha
 
rivate Sub contractdata_AfterUpdate()

Dim lst As ListBox
Dim intI As Integer
Dim varItm As Variant
Set lst = Me!contractdata
Me!date = Null
Me!con = Null
Me!sold = Null
Me!ship = Null
' Print value of each column for each row.
For intI = 0 To lst.ListCount - 1
For Each varItm In lst.ItemsSelected
Me!date = Me!date & " " & lst.Column(0, varItm)
Me!con = Me!con & " " & lst.Column(1, varItm)
Me!sold = Me!sold & " " & lst.Column(2, varItm)
Me!ship = Me!ship & " " & lst.Column(3, varItm)


Next varItm
Next intI
End Sub
It put the data double in the test box and it doesn't go one line at a time, the sold text box is 2.5" wide so it put the data right next to each other, ahahhahah, ,hehe, listboxes gone wild. thks
zypha
 
This code worked, after search through this site I found the cure Thanks.
Dim lst As ListBox
Dim varItm As Variant
Set lst = Me!contractdata
Me!date = Null
Me!con = Null
Me!sold = Null
Me!ship = Null
' Print value of each column for each row.

For Each varItm In lst.ItemsSelected
Me!date = Me!date & vbCrLf & lst.Column(0, varItm)
Me!con = Me!con & vbCrLf & lst.Column(1, varItm)
Me!sold = Me!sold & vbCrLf & lst.Column(2, varItm)
Me!ship = Me!ship & vbCrLf & lst.Column(3, varItm)


Next varItm

Thks Zypha
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top