Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    cindyLiu is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Aug 2014
    Posts
    48

    Doesn't work with combo box with ALL options

    Hello there,



    I need to use a combo box with all options in the month list. But only "ALL" shows the correct result. Rest, no matter which month I select, the result still shows the same result as selecting "ALL".
    Please help!

    here is my query:

    SELECT distinct ReMonth As Filter, ReMonth from TBL_Student
    UNION select distinct "*" As Filter, "All" as ReMonty from TBL_Student
    ORDER BY ReMonth;

    Thanks,
    Cindy

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    That's the query for combobox RowSource.

    What is query that uses combobox as criteria?
    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.

  3. #3
    cindyLiu is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Aug 2014
    Posts
    48
    yes, that is the query for combo box RowSource. after select a month (or All) from the combo box, then a report should be opened. here is the test query which is for the report.

    SELECT TBL_Student.[Temp-ID], TBL_Student.ReMonth, TBL_Student.Today, TBL_Student.Last_Name, TBL_Student.First_Name, TBL_Student.Gender, TBL_Student.BirthDate, TBL_Student.SchoolYear, TBL_Student.HomeLanguage, TBL_Student.Sibling, TBL_Student.Parent_LastName, TBL_Student.Parent_FirstName, TBL_Student.Parent_Phone, TBL_Student.Relationship
    FROM TBL_Student;

    Thanks,
    Cindy

  4. #4
    cindyLiu is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Aug 2014
    Posts
    48
    Maybe need some VB code in the report?
    Thanks,
    Cindy

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Quote Originally Posted by cindyLiu View Post
    yes, that is the query for combo box RowSource. after select a month (or All) from the combo box, then a report should be opened. here is the test query which is for the report.

    SELECT TBL_Student.[Temp-ID], TBL_Student.ReMonth, TBL_Student.Today, TBL_Student.Last_Name, TBL_Student.First_Name, TBL_Student.Gender, TBL_Student.BirthDate, TBL_Student.SchoolYear, TBL_Student.HomeLanguage, TBL_Student.Sibling, TBL_Student.Parent_LastName, TBL_Student.Parent_FirstName, TBL_Student.Parent_Phone, TBL_Student.Relationship
    FROM TBL_Student;

    Thanks,
    Cindy
    No criteria in that SQL?
    You have at least have to add criteria if criteria needs to be applied.

    As you have it now, that selects everything.

    You could just open the report with criteria, if needed and leave the query alone.
    That is how I would probably approach it.
    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
    cindyLiu is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Aug 2014
    Posts
    48
    for this report, I use 3 combo box for selecting inputs:
    select month, Siteassigned, and Registrar. I use cascading combos for the last 2 combo box, and they work fine. But when I added the Select Month (pass the month), then the result for the select month is not correct.

    I can attached a simple Access database to show you. but I don't know how to do it.

    Thanks,
    Cindy

  7. #7
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Look at the top of the forum window for "How to Attach Files" link.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  8. #8
    cindyLiu is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Aug 2014
    Posts
    48

    Please see attached files

    Simple1.accdbSimple 2.accdb


    please add all the tables from simple1 to simple2.

    Thanks,
    Yixin

  9. #9
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Quote Originally Posted by cindyLiu View Post
    for this report, I use 3 combo box for selecting inputs:
    select month, Siteassigned, and Registrar. I use cascading combos for the last 2 combo box, and they work fine. But when I added the Select Month (pass the month), then the result for the select month is not correct.
    Maybe the combos work fine as cascading combos, but don't you have your answer in post 5? You're not making use of the combo selections in that query sql so sure, it's going to behave as if you chose All. You need a Where clause in that sql to filter the results.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  10. #10
    cindyLiu is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Aug 2014
    Posts
    48
    this part doesn't work, so i removed: WHERE (((TBL_Student.Month)=[Forms]![FRM_OfficeRegistrar]![MonthSelect])

    here is the query for Q_Report1 before:

    SELECT TBL_Student.[Temp-ID], TBL_Student.Month, TBL_Student.Today, TBL_RegistrarTab.SIS_ID, TBL_Student.Last_Name, TBL_Student.First_Name, TBL_Student.Gender, TBL_Student.BirthDate, TBL_Student.SchoolYear, TBL_Student.HomeLanguage, TBL_Student.Sibling, TBL_Student.Parent_LastName, TBL_Student.Parent_FirstName, TBL_Student.Parent_Phone, TBL_Student.Relationship, TBL_Student.ReSiteAssigned, TBL_Student.Registrar, TBL_Student.ReAptDate, TBL_Student.Comments, TBL_RegistrarTab.Status, TBL_CompletionTab.StudentAttending
    FROM (TBL_Student LEFT JOIN TBL_RegistrarTab ON TBL_Student.[Temp-ID] = TBL_RegistrarTab.[Temp-ID]) LEFT JOIN TBL_CompletionTab ON TBL_Student.[Temp-ID] = TBL_CompletionTab.[Temp-ID]
    WHERE (((TBL_Student.Month)=[Forms]![FRM_OfficeRegistrar]![MonthSelect]) AND ((TBL_Student.ReSiteAssigned)=[Forms]![FRM_OfficeRegistrar]![ReSiteCom]) AND ((TBL_Student.Registrar)=[Forms]![FRM_OfficeRegistrar]![RegistrarCom]) AND ((TBL_CompletionTab.StudentAttending)=False));

  11. #11
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    I'd like to copy that and test, but it pastes as nonsense - probably because you didn't use code tags, but I don't think I've ever seen that problem here before.
    Here's what works
    Code:
    WHERE (((TBL_Student.ReSiteAssigned)=[Forms]![FRM_OfficeRegistrar]![ReSiteCom]) AND 
    ((TBL_Student.Registrar)=[Forms]![FRM_OfficeRegistrar]![RegistrarCom]) AND ((TBL_CompletionTab.StudentAttending)=False));
    but it looks the same as yours. Are you altering the query and opening the report without saving query design changes? If so, it will open the report based on the last saved version of the query. Maybe just bad data, but it sure is the wrong date in the report (based on the field label).

    Click image for larger version. 

Name:	11CLrpt.jpg 
Views:	21 
Size:	18.8 KB 
ID:	47568

    Not related, but
    - if you're going to require all fields to have data, you should not open the report if any required ones are empty
    - I would definitely advise against using reserved words for anything (IsLoaded has got to be reserved, and you're using it as a function name). Month also a no-no. Today is specific to Excel AFAIK, so while likely OK in Access, I still wouldn't use. Besides, it doesn't make sense as a field name as you're using it (to me at least).
    - shouldn't use any special characters in object names either (save for underscore). You're using dash/minus signs.
    - spelling of female might come back to bite you.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  12. #12
    cindyLiu is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Aug 2014
    Posts
    48
    I changed my query, and only select "All" got empty, rest months work fine.
    how can i fix my query?

    SELECT TBL_Student.[Temp-ID], TBL_Student.ReMonth, TBL_Student.Today, TBL_RegistrarTab.SIS_ID, TBL_Student.Last_Name, TBL_Student.First_Name, TBL_Student.Gender, TBL_Student.BirthDate, TBL_Student.SchoolYear, TBL_Student.HomeLanguage, TBL_Student.Sibling, TBL_Student.Parent_LastName, TBL_Student.Parent_FirstName, TBL_Student.Parent_Phone, TBL_Student.Relationship, TBL_Student.ReSiteAssigned, TBL_Student.Registrar, TBL_Student.ReAptDate, TBL_Student.Comments, TBL_RegistrarTab.Status, TBL_CompletionTab.StudentAttending
    FROM (TBL_Student LEFT JOIN TBL_RegistrarTab ON TBL_Student.[Temp-ID] = TBL_RegistrarTab.[Temp-ID]) LEFT JOIN TBL_CompletionTab ON TBL_Student.[Temp-ID] = TBL_CompletionTab.[Temp-ID]
    WHERE (((TBL_Student.ReMonth)=[Forms]![FRM_OfficeRegistrar]![MonthSelect]) AND ((TBL_Student.ReSiteAssigned)=[Forms]![FRM_OfficeRegistrar]![ReSiteCom]) AND ((TBL_Student.Registrar)=[Forms]![FRM_OfficeRegistrar]![RegistrarCom]));

  13. #13
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    What I'd probably do is build the sql in code and (perhaps) remove the constraint to use all controls. Yes, you could probably do this with only the query by incorporating Is Null in the sql but it makes for a bit of a mess in design view if you need to work with it later. However, maybe your issue is bad data. I'm getting 4 records with September/Dunn Loring/Andera, one of which is for student id 2222 and you don't even have that student id in student table. That is because of the outer joins in your query. I would think they should be inner joins. Gotta walk the mutt before I do any more looking.

    EDIT - so with All I do get records and you do not. Strange. Maybe I played with something else and forgot about it. Will post your db later. Make sure the tables you posted are the ones you're really using.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  14. #14
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Many ways to skin this cat
    - use query that has a test for null in the criteria
    - code as if all criteria inputs must be chosen
    - code for any optional choices; trickier but more dynamic

    I took the last approach, or else your code needed to also be modified so that once chosen, values could not be deleted, which is possible as you have designed the form. I don't see the point in the IsLoaded function (at least not as written) so put it back if you need it (it's commented out). One thing I learned here is that you cannot modify the recordsource property for a report that you're opening in Print Preview, so it required a work around. I used OpenArgs property for the report (it can handle some 32K characters). There are other options I could have used that I probably shouldn't go into as this is probably complicated enough for you as it is.

    You also should have Option Explicit in every module (I do) - the setting is in vb editor. Caused me grief because of a mis-spelling. I also added the NoData event in case options chosen result in no records.

    I presume that your tables db is a separate back end, so I linked your tables db to the front end (the one with the forms/reports/etc.). I don't see the point of having the student table in the front end, though.

    Anyway, play with it and see what you think. In the end, your major problem with All is that your query contains no criteria for the month values, so it wouldn't matter what you chose.

    Simple 2.zip
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  15. #15
    cindyLiu is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Aug 2014
    Posts
    48
    Thanks, Micron!
    but "All" still does not work.
    In Oracle, we can use this in query: in ('August','July','June','September').
    So I changed my query, but it still doesn't work.


    SELECT distinct ReMonth As Filter, ReMonth from TBL_Student
    UNION select distinct "*" As Filter, "All" as ReMonty from TBL_Student
    WHERE Remonth in ('August','July','June','September')
    ORDER BY ReMonth;

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 01-13-2022, 02:14 AM
  2. Replies: 4
    Last Post: 04-14-2020, 05:44 AM
  3. Replies: 3
    Last Post: 07-04-2017, 07:22 AM
  4. what options do i have to protect my work?
    By fdelval in forum Security
    Replies: 7
    Last Post: 02-09-2012, 10:46 PM
  5. Combo box doesn't work properly
    By joe1987 in forum Forms
    Replies: 9
    Last Post: 11-10-2011, 04:34 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