Results 1 to 2 of 2
  1. #1
    Khalil Handal is offline Competent Performer
    Windows 10 Access 2010 32bit
    Join Date
    Jun 2016
    Posts
    310

    Value of combo box with condition from value of another combo box

    Hi to all


    I have a bounded form with combo boxes. One combo box is for school years cboSchoolYear, and a second combo box for Students Names cboStudentName.
    My goal is to show students for the selected school year only.

    Control source for cboSchoolYear = fkSchoolYears
    row source of is:
    Code:
    SELECT tblSchoolYears.pkSchoolYears, tblSchoolYears.SchoolYear FROM tblSchoolYears ORDER BY tblSchoolYears.SchoolYear DESC;

    Control source for cboStudentName = fkStudentGrade
    Row source of cboStudentName is qryStudentsLookup


    Where qryStudentsLookup is:
    Code:
    SELECT tblStudents.pkIdNumber, [FirstName] & " " & [FathersName] & " " & [GrandFatherName] & " " & [FamilyName] AS Student
    FROM tblSchoolYears INNER JOIN (tblStudents INNER JOIN tblJoinStudentsYears ON tblStudents.pkIdNumber = tblJoinStudentsYears.fkStudentGrade) ON tblSchoolYears.pkSchoolYears = tblJoinStudentsYears.fkSchoolYears
    WHERE (((tblSchoolYears.pkSchoolYears) Like [Forms]![frmMarksMain]![cboSchoolYear]))
    GROUP BY tblStudents.pkIdNumber, [FirstName] & " " & [FathersName] & " " & [GrandFatherName] & " " & [FamilyName]
    ORDER BY [FirstName] & " " & [FathersName] & " " & [GrandFatherName] & " " & [FamilyName];


    Without the following criteria:
    [Forms]![frmMarksMain]![cboSchoolYear]
    The query shows ALL students; adding the WHERE criteria:
    [Forms]![frmMarksMain]![cboSchoolYear]
    Does not show any students at all (No records at all).

    Note: The criteria in query design view does not accept the following:
    Like [Forms]![frmMarksMain]![cboSchoolYear].column(0)


    Any suggestions?

    Khalil

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,574
    When you use Like you need to include an * I believe, one side or the other, or both.
    You just want =

    Always build your queries in small steps. Get the criteria correct, then add additional fields, and then the sort order/Grouping etc.
    It would also depend on what column is bound in your first combo as well.
    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

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

Similar Threads

  1. Replies: 9
    Last Post: 12-12-2023, 08:09 PM
  2. Replies: 7
    Last Post: 03-30-2015, 10:04 AM
  3. Replies: 2
    Last Post: 10-21-2014, 07:57 AM
  4. Replies: 2
    Last Post: 08-16-2012, 10:02 PM
  5. Replies: 4
    Last Post: 08-16-2011, 05:54 PM

Tags for this Thread

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