Dynamically Change Combo Box Data

Samanathon

New Member
Joined
Apr 22, 2002
Messages
12
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 (ie: currently, this combobox has 4 items. The user wants to add another item. They click a button, input data into another userform. Now the combobox has 5 items).

:rolleyes: My worksheet has two userforms: urfmShow_Information & urfmAdd_Airline.

urfmShow_Information has a combobox: cboAirlines

Userform urfmAdd_Airline has a textbox txtAdd_Airline and a button: cboAdd_Airline

So, the user wants to add a new airline to the combobox cboAirlines. They would click a button to load the userform urfmAdd_Airline, enter info into the textbox txtAdd_Airline and click the button cboAdd_Airline.

Now, the new info has been entered into combobox cboAirlines on the userform urfmAdd_Airline.

Any ideas?
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Add this code for the cboAddAirline:

Code:
Private Sub cboAddAirline_Click()
    urfmShow_Information.cboAirlines.AddItem Me.txtAdd_Airline.Value
    Unload Me
End Sub

Put some code into the cboAdd_Airline_Click event to show the urfmAdd_Airline form.

You will need to store the values of the ComboBox somewhere, else they will be lost when you close the form
 
Upvote 0
This is the code for frmShow_Infromation:

Private Sub cmbAbout_Click()
frmAbout_Me.Show
End Sub

Private Sub cmbAdd_Airline_Click()
frmAdd_Airline.Show
End Sub

Private Sub cmbCancel_Click()

Message = "Are you sure you want to close the form?"
'This will ask the user to confirm that they
' wish to close the Userform.
If MsgBox(Message, vbYesNo) = vbYes Then
Hide
'If they click "Yes", then it will close!
End If
'If they click "No", the comfirmation box closes.

End Sub

Private Sub cmbInput_Show_Click()

Rows("24:24").Select
Selection.Insert Shift:=xlDown
Selection.RowHeight = 12.75
Range("B24:G24").Select
Selection.Font.Bold = False
With Selection
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
Range("E24:F24").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Range("I24:J24").Select
With Selection.Interior
.ColorIndex = 15
.Pattern = xlSolid
End With
Range("J22:J23").Select
ActiveCell.FormulaR1C1 = "=SUM(R[2]C[-5]:R[5978]C[-5])"
Range("A1").Select


Sheet1.[b24] = txtShowName.Text
Sheet1.[c24] = txtCity.Text
Sheet1.[d24] = cboAirlines.Text
Sheet1.[e24] = txtSegments.Text
Sheet1.[f24] = cboMonth.Text
Sheet1.[g24] = txtNotes.Text
' ^^ These six will take the info from the
' text boxes and load them into the new row.

Unload Me

End Sub


This is the code for frmAdd_Airline:
Private Sub cmbAdd_Airline_Click()
frmShow_Information.cboAirlines.AddItem Me.txtAdd_Airline.Value
End Sub

Private Sub cmbCancel_Click()
frmAdd_Airline.Hide
End Sub
[/u][/i]
 
Upvote 0
You did not mention the error that you are getting.

The cmAddAirline_Click procedure is referring to `cboAirlines' combobox. Is this name correct?
 
Upvote 0
Yes, cboAirlines is the name of the combo box on the frmShow_Information user form.

Also, the error that I'm getting is:

Run-time error '70':
Permssion Denied


THANKS SO MUCH FOR YOUR HELP!!!!
 
Upvote 0
What line of code is causing the error?
 
Upvote 0
This one:

Private Sub cmbAdd_Airline_Click()
frmShow_Information.cboAirlines.AddItem Me.txtAdd_Airline.Value
Unload Me
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,825
Messages
6,121,787
Members
449,049
Latest member
greyangel23

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top