Connecting Tech Pros Worldwide Help | Site Map

From textBox To Listbox

Newbie
 
Join Date: Sep 2009
Posts: 9
#1: Sep 11 '09
"HI! im using the following code to fill a listbox from a textbox

Code:
Dim strNMBCY As Long
strNMBCY = Len(UserForm1.txtNMB)

If strNMBCY > 1 Then
UserForm2.ListBox1.AddItem UserForm1.txtNMB
UserForm2.ListBox2.AddItem UserForm1.txtNMB
End If

The problem is that it fills in a strange way Ex:
If I write in the textbox = Phill
It shows in the listbox like this =
P
Ph
Phi
Phil
Phill

Instead of only one word = Phill
CyberSoftHari's Avatar
Expert
 
Join Date: Sep 2007
Location: Banglore, India.
Posts: 450
#2: Sep 11 '09

re: From textBox To Listbox


check the event of the code part? i think it will be in textbox or form, keypress or key up or down events
Newbie
 
Join Date: Sep 2009
Posts: 9
#3: Sep 11 '09

re: From textBox To Listbox


Quote:

Originally Posted by CyberSoftHari View Post

check the event of the code part? i think it will be in textbox or form, keypress or key up or down events


The event is change, and with the other events is the same thing!! HELP PLEAASEEE
smartchap's Avatar
Familiar Sight
 
Join Date: Dec 2007
Location: Lucknow, India
Posts: 194
#4: Sep 12 '09

re: From textBox To Listbox


Since u have placed code in the Change event of txtNMB in UserForm1, as soon as u change any data in txtNMB (either delete a character or add a character) addition of content of txtNMB will take place in ListBox1 & ListBox2 in UserForm2. So I think u can put this code either in other command button or in the LostFocus event of txtNMB. Or u place the code in the KeyPress event of txtNMB with a check that if KeyPress is vbKeyReturn then go to the code like:
Expand|Select|Wrap|Line Numbers
  1. Private Sub TxtNMB_KeyPress(KeyAscii As Integer)
  2.   If KeyAscii = vbKeyReturn then
  3.      ......ur code here to add items to ListBoxes
  4.   End If
  5. End Sub
  6.  
Newbie
 
Join Date: Sep 2009
Posts: 9
#5: Sep 14 '09

re: From textBox To Listbox


Quote:

Originally Posted by smartchap View Post

Since u have placed code in the Change event of txtNMB in UserForm1, as soon as u change any data in txtNMB (either delete a character or add a character) addition of content of txtNMB will take place in ListBox1 & ListBox2 in UserForm2. So I think u can put this code either in other command button or in the LostFocus event of txtNMB. Or u place the code in the KeyPress event of txtNMB with a check that if KeyPress is vbKeyReturn then go to the code like:

Expand|Select|Wrap|Line Numbers
  1. Private Sub TxtNMB_KeyPress(KeyAscii As Integer)
  2.   If KeyAscii = vbKeyReturn then
  3.      ......ur code here to add items to ListBoxes
  4.   End If
  5. End Sub
  6.  



Thank you very much, I used the initialized event in the other form and it works perfectly.
Reply