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

populate txtbox with value from multi-selected list box, no skip txtbx 1

Status
Not open for further replies.

onusonu

MIS
Jun 21, 2005
18
0
0
US
The code below allows me to select multiple values from list box and automatically populate the selected values to textboxes. The problem is that if I select, say, item1, item2, and item 5, those items will populate txtbox1, txtbox2, and txtbox5, leaving txtbox3,4 empty.
How do I get it to populate the next empty textbox continuously?

Private Sub cmdOrder_Click()

Dim frm As Form, ctl As Control
Dim varItm As Variant
Dim intI As Integer

Set frm = Forms!PurchaseOrderForm
Set ctl = frm!lstItems
For intI = 0 To ctl.ItemsSelected.count - 1
For Each varItm In ctl.ItemsSelected
Me("Order" & CStr(varItm + 1)) = ctl.ItemData(varItm)
Next varItm
Next intI

End Sub
pj
 
Private Sub cmdOrder_Click()
Dim frm As Form, ctl As Control
Dim varItm As Variant
Dim intI As Integer
Set frm = Forms!PurchaseOrderForm
Set ctl = frm!lstItems
intI = 1
For Each varItm In ctl.ItemsSelected
Me("Order" & intI) = ctl.ItemData(varItm)
intI = intI + 1
Next varItm
End Sub

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top