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

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce

P Sitaram

Well-known Member
Joined
Jun 24, 2003
Messages
1,974
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
 

P Sitaram

Well-known Member
Joined
Jun 24, 2003
Messages
1,974
Can you post your code and also describe the error that you are getting?
 

Samanathon

New Member
Joined
Apr 22, 2002
Messages
12

ADVERTISEMENT

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]
 

P Sitaram

Well-known Member
Joined
Jun 24, 2003
Messages
1,974
You did not mention the error that you are getting.

The cmAddAirline_Click procedure is referring to `cboAirlines' combobox. Is this name correct?
 

Samanathon

New Member
Joined
Apr 22, 2002
Messages
12

ADVERTISEMENT

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!!!!
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,318
Office Version
  1. 365
Platform
  1. Windows
What line of code is causing the error?
 

Samanathon

New Member
Joined
Apr 22, 2002
Messages
12
This one:

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

Forum statistics

Threads
1,148,224
Messages
5,745,472
Members
423,953
Latest member
MrC54

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
Top