Updating drop down menus

spectraflame

Well-known Member
Joined
Dec 18, 2002
Messages
830
Office Version
  1. 365
Platform
  1. Windows
I have created a form with several drop down menus. The data in the drop down menus changes on a monthly basis. I created a Maint. Menu that will allow me to modify each drop down menu, but that really takes a great deal of time.

Is there a way to update the selections in the drop down list from my entry form? EX: When I get to a drop down list only has RED, GREEN, & BLUE as choices, I would like to be able to key in YELLOW and have that added as a choice next time.

I have tried the NOT IN LIST trigger, but I cannot seem to figure it out.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Matthew,

I have had this occassion arise. The way I get around it is to add a button next to the drop down box that says "Add New Item". This button is linked to an entry form which is created from the table the list is created from.

Keep in mind that you will have to requery to get the drop down box to immediately reflect the new entry after you enter it. Do this by entering the following VB code to your form:

Code:
Sub Form_Current()
   Me![drop down box name].Requery
End Sub

Hope this helps.
This message was edited by jmiskey on 2002-12-30 10:35
 
Upvote 0
Alternatively....

... you were on the right track with the notinlist event. Off the top of my head can't remember exactly how it works but you should find examples on the web without too much trouble. It will give you the flexibility of asking e.g. "Entry not in list. Would you like to add it?" etc.
 
Upvote 0
Thanks for getting me back on the right track. I thought that the notinlist feature was one of the ways to go. I will do some looking around for some examples.

Thanks again,
Matthew
 
Upvote 0
well since you asked nicely....

Create a table 'tblNames' with one field 'name'.

Create a form 'form1' with a combobox 'cboNames' which has a recordsource of SELECT [tblNames].[name] FROM tblNames;

Set the Limit to list property of the combo to Yes. Then in the limittolist event put the following code.

Code:
Option Compare Database
Option Explicit

Private Sub cboNames_NotInList(NewData As String, Response As Integer)
    ' You need a reference to ADO (ActiveX Data Objects) to run this code.
    
    ' You've set Limit To List = Yes which all things being equal
    ' will trigger an error message when you enter something which is not in the list
    ' By putting code here, you're getting the chance to step in before the error, and
    ' ask the user what (s)he's trying to achieve.
    '
    ' If the user says that they'd like to add it to the list then
    ' you've got to write the code to add it.
    ' Then you pass the 'Response' parameter value=acDataErrAdded
    ' which lets Access know to requery the combo etc..
    '
    ' If it was a genuine error then you pass one of the other constants (see below)
    ' The only difference between them is that one displays the original error message
    ' and the other one doesn't.
    ' DMCKinney.
    '
    ' The relevant constants.
    'acDataErrAdded
    'acDataErrContinue
    'acDataErrDisplay
    
    Dim rst As ADODB.Recordset
    
    Dim MyResponse As VbMsgBoxResult
    MyResponse = MsgBox(NewData & " is not in the list." & vbCrLf & "Do you want to add it?", vbYesNo, "Not in List")
    Select Case MyResponse
        Case vbYes
            Set rst = New ADODB.Recordset
            rst.Open "Select * from tblNames", CurrentProject.Connection, adOpenDynamic, adLockOptimistic
            rst.AddNew
                rst.Fields("Name").Value = NewData
            rst.Update
            rst.Close
            
            Set rst = Nothing
            Response = acDataErrAdded
            
        Case vbNo
            Response = acDataErrContinue
    End Select

    
End Sub
 
Upvote 0
DMC,

That is really cool! You have just made many of my drop downs so much easier to update.

Thank you again,

Matthew
 
Upvote 0
DMC,

I modified your code to reflect the names of my combo boxes and tables. Now I am getting the following error when something is not in the list:

Compile Error: User defined type not defined

Then when I click OK, it highlights in yellow

Private Sub Mfg_NotInList(NewData As String, Response As Integer)

and stops at

rst As ADODB.Recordset

I compared it to the way I set it up from your original example, and everything looks to be the same. Can you tell me some things that I may be missing??

Thanks,
Matthew
 
Upvote 0
you need a reference to ado. From the VBA window...
Tools...References...Microsoft ActiveX Data Objects 2.x
 
Upvote 0
DMC,

Thanks. I should have read your comments in the macro more closely.

Thanks again,
Matthew
 
Upvote 0

Forum statistics

Threads
1,221,503
Messages
6,160,195
Members
451,630
Latest member
zxhathust

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