Add value to my database if not currently in drop down liast

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,731
Office Version
  1. 2007
Platform
  1. Windows
I open my userform & start to add customers details along with selecting his vehicle from a drop down box.
Sometimes the value isnt present so i need to close userform, add value to worksheet database, open userform then start gain.

So now i wish if this occurs as opposed to doing all the above be able to keep the userform open, add the new value to worksheet database & continue once added by selecting it from drop down.

Some infor for you if needed.
Form is called CloningForm
Drop down box in question is called ComboBox5
Worksheet database is called DATABASE INFO
Column for it to be added is Column E

As values are already in Column E the code will need to add to the end of what is currently there.

I am not sure how the updated value will work in respect of refreshing / closing the drop down just selected.

Thanks
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Hi there,

Here's one way (you will have to add a new button which I've called "cmdAddNew"):

VBA Code:
Option Explicit
Private Sub cmdAddNew_Click()

    Dim varNewValue As Variant
    
    varNewValue = InputBox("Enter the desired value for Col. E:")
    
    If Len(varNewValue) > 0 Then
        ThisWorkbook.Sheets("DATABASE INFO").Range("E" & Rows.Count).End(xlUp).Offset(1, 0).Value = varNewValue
    End If

End Sub

You may have to also reset the range for ComboBox5.

Regards,

Robert
 
Upvote 0
Morning,
The new value is added to the column fine but i dont see it in the drop down.
How would i reset the combobox /
I added Combobox5.Clear but just gave me an error.

Please advise Thanks
 
Upvote 0
Hi there,

Try this:

VBA Code:
Option Explicit
Private Sub cmdAddNew_Click()
    
    Dim varNewValue As Variant
    
    varNewValue = InputBox("Enter the desired value for Col. E:")
    
    If Len(varNewValue) > 0 Then
        ThisWorkbook.Sheets("DATABASE INFO").Range("E" & Rows.Count).End(xlUp).Offset(1, 0).Value = varNewValue
        Me.ComboBox5.AddItem varNewValue
    End If

End Sub

If this doesn't work please post the code you're using to populate ComboBox5.

Robert
 
Upvote 0
I get permission denied,
Debug to this being the issue
Rich (BB code):
Me.ComboBox5.AddItem varNewValue

The value is added to the list on worksheet but fails i assume at combobox
 
Upvote 0
I get permission denied,

That's odd as it worked for me :confused: How do you initially populate the combo box when the form is opened?
 
Last edited:
Upvote 0
Hi,
Not at home at present but from memory when i right click Combobox5 properties at Row Source it showed Table 5

If we need to delete it from row source & add it another way then let’s do it so it’s working.

Thanks.
 
Upvote 0
If the data is in a table try this:

VBA Code:
Option Explicit
Private Sub UserForm_Activate()

    Dim tblSource As ListObject
    Dim varComboBoxData As Variant

    Set tblSource = Worksheets("DATABASE INFO").ListObjects("Table5") 'Assumes the data is in Table5 from the 'DATABASE INFO' tab.  Change to suit.
    varComboBoxData = tblSource.DataBodyRange
    Me.ComboBox5.List = varComboBoxData

End Sub
Private Sub cmdAddNew_Click()
    
    Dim varNewValue As Variant, varComboBoxData As Variant
    Dim lngNewRecRow As Long
    Dim tblSource As ListObject
    
    varNewValue = InputBox("Enter the desired value for Col. E:")
    
    If Len(varNewValue) > 0 Then
        lngNewRecRow = ThisWorkbook.Sheets("DATABASE INFO").Cells(Rows.Count, "E").End(xlUp).Row + 1
        ThisWorkbook.Sheets("DATABASE INFO").Range("E" & lngNewRecRow).Value = varNewValue 'Adding a record to a table will automatically resize it
        Set tblSource = Worksheets("DATABASE INFO").ListObjects("Table5") 'Assumes the data is in Table5 from the 'DATABASE INFO' tab.  Change to suit.
        varComboBoxData = tblSource.DataBodyRange
        Me.ComboBox5.List = varComboBoxData
    End If

End Sub
 
Upvote 0
I get the same denied message now when i just open the fofrm.

Shall i upload my workbook ?
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,191
Members
452,616
Latest member
intern444

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