Results 1 to 4 of 4
  1. #1
    Kaloyanides is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Jan 2015
    Location
    Arlington, MA
    Posts
    51

    Why won't this work? Union Query (Only display active records [check box not selected])

    I can't seem to limit this query to only active records. Active = ckInactive NOT selected in tblEmployees.



    SELECT tblEmployees.EmployeeID, UCASE([UserName]) AS FullName, 1 As SortColumn, tblEmployees.ckinactive FROM tblEmployees UNION SELECT 0,"<NEW EMPLOYEE>",0,0 FROM tblEmployees
    WHERE tblEmployees.ckinactive = false
    ORDER BY SortColumn, fullname;

    Thanks!

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    You need the WHERE on both queries.
    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

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    i usu build all my queries, then:
    select * from query1
    union
    select * from query2

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    second query doesn't require a where clause, but the first one does. Try

    Code:
    SELECT tblEmployees.EmployeeID, UCASE([UserName]) AS FullName, 1 As SortColumn, tblEmployees.ckinactive 
    FROM tblEmployees
    WHERE tblEmployees.ckinactive = false
    UNION SELECT 0,"<NEW EMPLOYEE>",0,0 FROM tblEmployees
    ORDER BY SortColumn, fullname;
    alternatively try

    Code:
    SELECT * FROM
    (SELECT tblEmployees.EmployeeID, UCASE([UserName]) AS FullName, 1 As SortColumn, tblEmployees.ckinactive 
    FROM tblEmployees
    UNION SELECT 0,"<NEW EMPLOYEE>",0,0 FROM tblEmployees) Q
    WHERE Q.ckinactive = false
    ORDER BY SortColumn, fullname;

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

Similar Threads

  1. Replies: 9
    Last Post: 10-20-2022, 06:19 AM
  2. Replies: 2
    Last Post: 01-01-2022, 12:52 PM
  3. Replies: 4
    Last Post: 08-09-2017, 12:06 PM
  4. Replies: 1
    Last Post: 09-02-2015, 01:16 AM
  5. Replies: 0
    Last Post: 12-28-2008, 01:56 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