View Full Version : Solved: Popularize Listbox using Textbox
marreco
03-09-2013, 06:21 PM
Hi.
it is possible to popularize Listbox, Textbox using?
I have a form with 4 textbox, I would like to send the data entered in textboxs for the listbox.
Private Sub CommandButton1_Click()
Dim txt As String
With Me.ListBox1
.AddItem
For i = 1 To 4
txt = Me.Controls("TextBox" & i).Value
'MsgBox .ListCount
.List(.ListCount - 1, i - 1) = txt
.List(.ListCount - 1, i - 2) = txt
.List(.ListCount - 1, i - 3) = txt
.List(.ListCount - 1, i - 4) = txt
Next i
End With
End Sub
Doug Robbins
03-10-2013, 01:19 AM
Use:
Private Sub CommandButton1_Click()
Dim txt As String
With Me.ListBox1
For i = 1 To 4
txt = Me.Controls("TextBox" & i).Value
AddItem.txt
Next i
End With
End Sub
marreco
03-10-2013, 06:33 AM
Hi.
generated an error message
Copile error:
Variable not defined
Private Sub CommandButton1_Click()
ListBox1.list=array(textbox1.text,textbox2.text,textbox3.text,textbox4.text )
End Sub
Doug Robbins
03-10-2013, 02:23 PM
Marreco,
You need to declare i as long
Dim i as Long
marreco
03-11-2013, 05:37 PM
Hi.
I must not have explained right.
I need to appear in ListBox1.List, the data from one side of the other.
example:
When naTextBox1 entered, the data would be entered as if it were in the Column1
When naTextBox2 entered, the data would be entered as if it were in the Column2
When naTextBox3 entered, the data would be entered as if it were in the column3
When naTextBox5 entered, the data would be entered as if it were in the coluna4
it is possible
Greetings Marreco,
Could you attach a wb with what you want to do? Preferably in .xls format.
Mark
marreco
03-12-2013, 08:36 AM
Hi
see file
Kenneth Hobs
03-12-2013, 12:18 PM
Private Sub CommandButton1_Click()
Dim txt As String, i As Integer, a() As Variant
With ListBox1
.Clear
.ColumnCount = 4
ReDim a(1 To 1, 1 To 4)
For i = 1 To 4
txt = Me.Controls("TextBox" & i).Value
a(1, i) = txt
Next i
.List = a()
End With
End Sub
Doug Robbins
03-12-2013, 02:51 PM
Assuming that you want to insert multiple rows of data into the listbox, use:
Private Sub CommandButton1_Click()
Dim txt As String, i As Long
With ListBox1
.ColumnCount = 4
i = 1
.AddItem Me.Controls("TextBox" & i).Text
For i = 2 To 4
.List(.ListCount - 1, i - 1) = Me.Controls("TextBox" & i).Text
Next i
'Clear textbox controls ready for entry of next data
For i = 1 To 4
Me.Controls("textBox" & i).Text = ""
Next i
i = 1
Me.Controls("textBox" & i).SetFocus
End With
End Sub
marreco
03-12-2013, 03:19 PM
Hi.
I was very happy with both answers
Doug Robbins and Kenneth Hobs, thank you very much!!
@Doug
Why not ?
Private Sub CommandButton1_Click()
With ListBox1
.ColumnCount = 4
.AddItem
For i = 1 To 4
.List(.ListCount - 1, i - 1) = Me("TextBox" & i).Text
Me("TextBox" & i).Text =""
Next
end With
End Sub
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.