Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Adding items from Listbox to empty textbox

I have a form with 24 textboxes on it.
The form has a populated listbox with data from a sheet.
I want to be able to have the user clcik on any item in the
listbox(Listbox1) and the selected value to be placed intoa Textbox.
But how do i get the value to be placed into the next available (empty)
Textbox from 1-24 ?


Corey....


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 343
Default Adding items from Listbox to empty textbox

Try this:

Private Sub ListBox1_AfterUpdate()
If TextBox1.Value = "" Then
TextBox1.Value = ListBox1.Value
GoTo Finished
End If

If TextBox2.Value = "" Then
TextBox2.Value = ListBox1.Value
GoTo Finished
End If

If TextBox3.Value = "" Then
TextBox3.Value = ListBox1.Value
GoTo Finished
End If

' continue for the rest of the TextBoxes


Finished:
End Sub
"Corey ...." wrote in message
...
I have a form with 24 textboxes on it.
The form has a populated listbox with data from a sheet.
I want to be able to have the user clcik on any item in the
listbox(Listbox1) and the selected value to be placed intoa Textbox.
But how do i get the value to be placed into the next available (empty)
Textbox from 1-24 ?


Corey....


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Adding items from Listbox to empty textbox

If you name the textboxes nicely (TextBox1, Textbox2, ..., textbox24), you could
use code like:

Option Explicit
Private Sub ListBox1_Change()
Dim MaxNumberOfTextBoxes As Long
Dim AssignedTheValue As Boolean
Dim iCtr As Long

MaxNumberOfTextBoxes = 24

If Me.ListBox1.ListIndex < 0 Then
'nothing selected
Exit Sub
End If

AssignedTheValue = False
For iCtr = 1 To MaxNumberOfTextBoxes
With Me.Controls("Textbox" & iCtr)
If .Value = "" Then
AssignedTheValue = True
.Value = Me.ListBox1.Value
Exit For
End If
End With
Next iCtr

If AssignedTheValue = False Then
Beep
MsgBox "No space available--what should happen?"
End If

End Sub
Private Sub UserForm_Initialize()
Dim iCtr As Long
With Me.ListBox1
.MultiSelect = fmMultiSelectSingle
For iCtr = 1 To 5
.AddItem "A" & iCtr
Next iCtr
End With
End Sub


But I think I wouldn't use the _Change event. I know as a user, I can make lots
of mistakes when trying to click on the correct item.

I'd use an "Ok" commandbutton on the form.

You can change:
Private Sub ListBox1_Change()
to:
Private Sub CommandButton1_Click()

"Corey ...." wrote:

I have a form with 24 textboxes on it.
The form has a populated listbox with data from a sheet.
I want to be able to have the user clcik on any item in the
listbox(Listbox1) and the selected value to be placed intoa Textbox.
But how do i get the value to be placed into the next available (empty)
Textbox from 1-24 ?

Corey....


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding items to columns in a listbox Daniel Bonallack Excel Discussion (Misc queries) 1 May 7th 07 04:45 PM
Adding Items to ListBox-eliminating Blanks jpendegraft[_9_] Excel Programming 10 July 16th 04 02:25 AM
Adding Items to a ListBox-Eliminating Blanks-Part II jpendegraft[_11_] Excel Programming 4 May 2nd 04 04:08 AM
Adding Items to a ListBox-Unique Items Only jpendegraft[_14_] Excel Programming 2 May 2nd 04 02:27 AM
Adding Items to a LISTBOX--eliminating Blank Lines jpendegraft[_8_] Excel Programming 2 May 1st 04 03:18 PM


All times are GMT +1. The time now is 10:32 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"