ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Dynamically adding data to a Combobox? (https://www.excelbanter.com/excel-programming/294081-dynamically-adding-data-combobox.html)

samanathon

Dynamically adding data to a Combobox?
 
Hi All!

For my first post . . . I NEED HELP!

I would like for a user to be able to click a button, a userform open
and the user can input data. This new data will be added to
combobox.

I have the userform and botton covered. I need help with the dynami
code for adding new data to the combobox!

Any ideas?

(ie: currently, this combobox has 4 items. The user wants to ad
another item. They click a button, input data into the userform. No
the combobox has 5 items

--
Message posted from http://www.ExcelForum.com


John Williams[_4_]

Dynamically adding data to a Combobox?
 
samanathon wrote in message ...
Hi All!

For my first post . . . I NEED HELP!

I would like for a user to be able to click a button, a userform opens
and the user can input data. This new data will be added to a
combobox.

I have the userform and botton covered. I need help with the dynamic
code for adding new data to the combobox!


Assuming your userform has TextBox1 and ComboBox1 on it, the following
code in the userform should do what you want:

Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger,
ByVal Shift As Integer)

If KeyCode = vbKeyReturn Then
KeyCode = 0

ComboBox1.AddItem TextBox1.Text
ComboBox1.ListIndex = 0

TextBox1.Text = ""
TextBox1.SetFocus

End If

End Sub

samanathon[_2_]

Dynamically adding data to a Combobox?
 
OK,

It didn't work, but let me specify a bit:

My worksheet has two userforms: Show_Information & Add_Airline.

Show_Information(userform) has: Airlines(combobox)

Add_Airline(userform) has Add_Airline(textbox) and Add_Airline(button)

So, the user wants to add a new airline to the Airlines(combobox). The
would click a button to load the Add_Airline(userform), enter info int
Add_Airline(textbox) and click Add_Airline(button).

Now, the new info has been entered into Airlines(combobox) on th
Add_Airline(userform).

Any ideas

--
Message posted from http://www.ExcelForum.com


count

Dynamically adding data to a Combobox?
 
Hi, Just one more piece of info from you:
How Airlines(combo) gets its list of choices? Is it named range? Is it
loaded through .AddItem? Is it empty at present?
I will then have an answer.

However, like you, I'd be happy to see most elegant solution.
I mean the solution that doesn't involve AddAirline form - just plain typing
away new (unmatched) text in Combo invokes MsgBox, asking if OK to add new
stuff in.
regards
Paul
Użytkownik "samanathon " napisał
w wiadomości ...
OK,

It didn't work, but let me specify a bit:

My worksheet has two userforms: Show_Information & Add_Airline.

Show_Information(userform) has: Airlines(combobox)

Add_Airline(userform) has Add_Airline(textbox) and Add_Airline(button)

So, the user wants to add a new airline to the Airlines(combobox). They
would click a button to load the Add_Airline(userform), enter info into
Add_Airline(textbox) and click Add_Airline(button).

Now, the new info has been entered into Airlines(combobox) on the
Add_Airline(userform).

Any ideas?


---
Message posted from http://www.ExcelForum.com/




John Williams[_4_]

Dynamically adding data to a Combobox?
 
samanathon wrote in message ...
OK,

It didn't work, but let me specify a bit:

My worksheet has two userforms: Show_Information & Add_Airline.

Show_Information(userform) has: Airlines(combobox)

Add_Airline(userform) has Add_Airline(textbox) and Add_Airline(button)

So, the user wants to add a new airline to the Airlines(combobox). They
would click a button to load the Add_Airline(userform), enter info into
Add_Airline(textbox) and click Add_Airline(button).

Now, the new info has been entered into Airlines(combobox) on the
Add_Airline(userform).

Any ideas?


---
Message posted from http://www.ExcelForum.com/


In your Add_Airline userform, put the following click event for the
Add_Airline command button:

Private Sub cmdAdd_Airline_Click()
If txtAdd_Airline.Text < "" Then
Show_Information.cboAirlines.AddItem txtAdd_Airline.Text
txtAdd_Airline.Text = ""
txtAdd_Airline.SetFocus
End Sub


If you want to persist the airlines you will have to store them in a
sheet somewhere and initialize the combobox items with the existing
airlines.


All times are GMT +1. The time now is 05:35 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com