Results 1 to 5 of 5
  1. #1
    ali_sh is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2019
    Posts
    21

    How to add one more item to row source of combo box that is referenced to a field

    Hello


    I have created a search form including ComboBox that is used to search based of, and I referenced row source of that to a field of a table and I want to add "ALL" item to list. Is there any SQL code to do that like using "UNION" operator?
    Thanks in advance

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    if the rowsource is a query to a table, put a button beside the combo to open the source table,
    the user adds the new entry,
    close the table/query
    click REFRESH ALL button in the top toolbar,
    new item is in the list/combo.

  3. #3
    accesstos's Avatar
    accesstos is offline Expert
    Windows XP Access 2007
    Join Date
    Dec 2018
    Location
    Greece
    Posts
    551
    Quote Originally Posted by ali_sh View Post
    Is there any SQL code to do that like using "UNION" operator?

    Of course!
    Code:
    SELECT "All"  FROM theTable 
    UNION 
    SELECT DISTINCT theField FROM theTable;

  4. #4
    ali_sh is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2019
    Posts
    21
    Quote Originally Posted by accesstos View Post
    Of course!
    Code:
    SELECT "All"  FROM theTable 
    UNION 
    SELECT DISTINCT theField FROM theTable;
    that worked and this is exactly what I want, thank you.

    I change that to following code:

    Code:
    SELECT "All"  FROM theTable 
    UNION 
    SELECT DISTINCT Field_1 FROM theTable ORDER BY theTable.Field_2;
    the part after UNION was working but when I added the new code line and UNION to the first, I got this error:

    The ORDER BY expression (theTable.Field_2) includes fiels that are not selected by the uery. Only those fields reuested in the first query can be included in an ORDER BY expression.

    I'll be grateful if you help me on this too.

  5. #5
    accesstos's Avatar
    accesstos is offline Expert
    Windows XP Access 2007
    Join Date
    Dec 2018
    Location
    Greece
    Posts
    551
    Happy to help!

    The best way to keep the list sorted and the word "All" at the top, is to create a separate query with SQL:
    Code:
    SELECT DISTINCT Field_1 FROM theTable ORDER BY theTable.Field_2
    and use its name in place of the "theTable". For example:

    Code:
    SELECT "All"  FROM theTable 
    UNION 
    SELECT DISTINCT Field_1 FROM theQuery;
    Cheers,
    John

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

Similar Threads

  1. Replies: 5
    Last Post: 10-20-2019, 05:51 PM
  2. Replies: 1
    Last Post: 10-21-2018, 08:42 AM
  3. Replies: 9
    Last Post: 03-14-2017, 04:40 AM
  4. Replies: 2
    Last Post: 02-19-2013, 04:02 PM
  5. Replies: 2
    Last Post: 04-15-2011, 01:13 PM

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