Results 1 to 12 of 12
  1. #1
    HansN is offline Novice
    Windows 10 Office 365
    Join Date
    Aug 2023
    Posts
    3

    Add free text to dropdown list

    Hello,

    I have in my form a dropdown list for "size", and the options in the list are: XS, S, M, L, XL.

    I would now also like to add an option for free text in this dropdown, for example to be able to type: "4mm"

    Is it possible to create such a dropdown list, where there are some predetermined options to choose from, but also an option to enter my own text?



    Thanks!

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    One option is to set the Limit to List to No, which should allow the user to type in free text.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Is this dropdown a combobox with ValueList as source?

    If you want to allow these 'free text' inputs to be included in list for future use, couple options with combobox set for Table/Query as source:

    1. lookup table as source for list and combobox NotInList event can be used to add new entries - combobox LimitToList Yes

    2. use the data table as source for list: SELECT DISTINCT Size FROM datatable; - combobox LimitToList No
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    HansN is offline Novice
    Windows 10 Office 365
    Join Date
    Aug 2023
    Posts
    3
    Thanks, I will try these suggestions!

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    I would go with the NotInList option.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  6. #6
    Edgar is offline Competent Performer
    Windows 8 Access 2016
    Join Date
    Dec 2022
    Posts
    274
    Hans, I'd say you have two options that depend on your context.

    Option 1. If your dropdown list is set to a list, not a table/query, then just set Limit To List to No and you can enter any value in your dropdown list, including those in the list.

    Option 2. If your dropdown list comes from a table/query, if it's a lookup table, then you could implement a popular approach which involves choosing a record labeled "Other" which then displays a textbox where you can write that "other" option. To do that, you need to:

    1. add a column to the table where you're storing the size, name it "OtherSize" or something similar
    2. add the record "Other" to your sizes table
    3. add a hidden textbox to your form, that is, set its visible property to No by default
    4. in the change event of your combo box, add the code to change its visible property to yes when "Other" is selected
    5. in the current event of the form, make sure that textbox is displayed when "Other" is selected, keep it hidden if "Other" is not selected
    6. when "Other" is selected, also make sure to set focus to the textbox now that is visible
    7. in the before update event of the form, ensure that if "Other" is selected, the textbox is not empty and viceversa

    Your users are probably familiar with this approach, it's widely used, although it is some work. Check the attached for more info.
    Attached Files Attached Files

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Whether combobox source is list or table, can have LimitToList set to No to enter anything into field.

    Are you suggesting having 2 fields for this input?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    Edgar is offline Competent Performer
    Windows 8 Access 2016
    Join Date
    Dec 2022
    Posts
    274
    Quote Originally Posted by June7 View Post
    Whether combobox source is list or table, can have LimitToList set to No to enter anything into field.
    Absolutely. However, allow me to remind you that, regardless of what LimitToList is set to, if the column has referential integrity applied, the constraint won't let you add values that don't belong to the list.

    Quote Originally Posted by June7 View Post
    Are you suggesting having 2 fields for this input?
    Yes. I'm suggesting having 2 fields/columns for the input of size in the context of this database and many other kinds of scenarios. Like Zip codes, countries, states, cities, genders, religions, medical conditions, pretty much anything with a "type of ___" that can have additional options that do not appear in the default list.

    Having 2 fields is used when you want to maintain the constraints. It's up to the developer to determine if it's optimal for the database.

  9. #9
    Join Date
    Apr 2017
    Posts
    1,681
    One possible way to do this is:
    1. Set LimitToList to No (NB! As I remember, to make this to work properly the RowSource of combo must be single-column one!);
    2. Set RowSource of combo as like "SELECT DISTINCT SourceField FROM FormSourceTable ORDER BY 1".

    Now in your combo you can select any value inserted into SourceField previously. You can enter any new value into combo too, and next time you select a value in your combo, this value is displayed in selection list too.

  10. #10
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Was suggested in post #3.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  11. #11
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    I have a table, tblTaskList, which consists of 2 fields - TaskLstID and strTask.

    The combo box (named txtTask) rowsource is "SELECT tblTaskList.TaskLstID, tblTaskList.strTask FROM tblTaskList;"

    The bound field in the combo is 2, the text field, not 1 the primary key field.
    Limit to list is no. The combo is bound to a field in tblTasks.

    When a user types in a new task that is not in the list I use an after update event to mimick the not in list event.

    Code:
    Private Sub txtTask_AfterUpdate()
    
        If DCount("*", "tblTaskList", "strTask = """ & Me.txtTask & """") = 0 Then
    
            Select Case MsgBox(Chr(34) & UCase(Me.txtTask) & Chr(34) & " is not in the list." & vbNewLine & vbNewLine & "Do you want to save it for future use?", vbYesNo, "Confirm Save")
    
                Case vbYes
                    CurrentDb.Execute ("Insert into tblTaskList(strTask) values(""" & Me.txtTask & """)"), dbFailOnError
                    Me.txtTask.Requery
                Case vbNo
    
            End Select
    
        End If
    
    End Sub
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  12. #12
    HansN is offline Novice
    Windows 10 Office 365
    Join Date
    Aug 2023
    Posts
    3
    Thanks for all the great advice, I will try your suggestions!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Function to pull date from free-text field.
    By ry94080 in forum Programming
    Replies: 6
    Last Post: 11-30-2022, 07:51 PM
  2. Replies: 3
    Last Post: 06-24-2017, 07:37 AM
  3. Free text within a report
    By Scott488 in forum Reports
    Replies: 3
    Last Post: 11-11-2013, 12:25 PM
  4. a Question about Free text in a report.
    By fedesc in forum Access
    Replies: 3
    Last Post: 10-26-2011, 11:31 AM
  5. Inputting Free text in Form
    By maintt in forum Forms
    Replies: 2
    Last Post: 08-13-2010, 11:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums