Results 1 to 10 of 10
  1. #1
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776

    Adding (All) to a combo box

    Hi all,
    I have an unbound form that i am using to open a report.Has a combo on it that populates with HelperValues from a table. I want to add an "All" to the combo so that it will put all the records on that form to my report.



    The after update event is:

    Code:
    Private Sub CboMemberRoleSelect_AfterUpdate()
         DoCmd.OpenReport "Report2", acViewPreview, , "MemberRoleID=" & Me.CboMemberRoleSelect
         DoCmd.Close acForm, Me.Name
    End Sub
    The RowSource is:
    Code:
    SELECT HelperID, HelperTypeID,HelperValue FROM tblHelper UNION SELECT 0, '(All)' FROM tblHelper WHERE HelperTypeID=14 ORDER BY [HelperValue];
    Error is:
    The number of columns in the two selected tables or queries of a union query do not match

    Without the UNION SELECT 0, '(All)' FROM tblHelper in the rowsource I can select the HelperValue i want and it opens the report just fine to that specific selection. I want to add the "All" so that it will
    open report to all of the helpervalues....not just one.

    Hope this makes some sense,

    Thanks
    Dave

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    It's simple really. Each part of a UNION query must have the same number of fields as the message says. Either add another bogus field to one query part or restrict both parts to one column, whichever looks and works better. If you're showing 2 or 3 columns I imagine the bogus columns are going to look strange.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    Code:
    SELECT HelperID, HelperTypeID,HelperValue FROM tblHelper UNION SELECT 0, '(All)' FROM tblBogus UNION SELECT 0, '(All)' FROM tblBog UNION SELECT 0, '(All)' FROM tblHelp WHERE HelperTypeID=14 ORDER BY [HelperValue];
    I am going to guess this is not what you are talking about...Never having to do this before, what the heck?
    Thanks

  4. #4
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    I tried this but still no success. Get a totally new error when trying this one out....

    Code:
    SELECT HelperID, HelperValue FROM tblHelper UNION SELECT 0,  '(All)' FROM tblBogus UNION SELECT 1, '(All)' FROM tblBogus WHERE HelperTypeID=14 ORDER BY [HelperValue];

  5. #5
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    OK, I got this to actually work with one exception, it gives me all the names in the tblHelper, its like the ware clause is not working?

    Code:
    SELECT HelperID, HelperValue FROM tblHelper UNION SELECT '0', ' All' FROM tblHelper WHERE HelperTypeID=14 ORDER BY [HelperValue];

  6. #6
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    Repeating sections in multiple UNIONs is not what I had in mind. If the first query returns 3 fields, the second query must also contain 3 fields. In fact, every one after the first must contain 3. Using your original, more like
    Code:
    SELECT '(All)',0,0 UNION SELECT HelperID, HelperTypeID,HelperValue FROM  tblHelper WHERE HelperTypeID=14 ORDER BY [HelperValue];
    I have no idea if that will work because the data in your fields isn't known.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    I did get this to limit the list to what is in the Where statement (HelperTypeID=14) and the All is in the list but when you select all, it opens report blank

    Code:
    SELECT HelperID, HelperValue FROM tblHelper WHERE HelperTypeID=14  UNION SELECT '0', '(All)' FROM tblHelper ORDER BY [HelperValue];

  8. #8
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    Hi Micron,
    Thanks for all the suggestions. I was able to get this to do what I wanted yet it if I click on all it does not populate the report with any data. Do I need to put some vba in that to make that happen? If I select all it should do all of the fields that are in that tbl i would think....
    Code:
    SELECT HelperID, HelperTypeID, HelperValue FROM tblHelper WHERE HelperTypeID=14 UNION SELECT 0,0,'(All)' FROM tblHelper ORDER BY [HelperValue];
    Data is HelperID = AutoNum, HelperTypeID = Number, HelperValue = Text
    Last edited by d9pierce1; 03-30-2021 at 07:29 PM. Reason: correction, added data types

  9. #9
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    If you pick a value from such a combo, you filter a report or form based on that value. If you choose ALL you don't filter.
    OR you open the form/report with a recordsource that has a WHERE clause using the value or use a recordsource that doesn't use a WHERE clause.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  10. #10
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    Hi all,
    I thank you for the input. I ended up going with a list box and after reviewing some Allen Brown info, i was able to solve this and make it even better. Thank you Allen.... So, i will consider this solved.
    dave

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

Similar Threads

  1. Adding New Record Using Combo Box
    By ahuffman24 in forum Access
    Replies: 12
    Last Post: 06-21-2019, 08:27 AM
  2. Adding Totals to Combo Box
    By adamjon92 in forum Forms
    Replies: 5
    Last Post: 02-25-2016, 02:36 PM
  3. Adding a Combo Box
    By Pucklvr001 in forum Access
    Replies: 1
    Last Post: 06-02-2014, 09:12 PM
  4. adding a record through a combo box
    By sssandhya89 in forum Access
    Replies: 11
    Last Post: 03-15-2013, 11:23 AM
  5. Adding to combo box
    By NISMOJim in forum Access
    Replies: 3
    Last Post: 01-29-2011, 03:16 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