Results 1 to 6 of 6
  1. #1
    mroberts is offline Novice
    Windows Vista Access 2007
    Join Date
    Jul 2013
    Posts
    10

    DISTINCTROW Issue

    I am running an aggregate query on student and student attendance tables in which they are never absent (attendance status <> anything but present). I am using DISTINCTROW to return only one instance of the student name even though they will have many records meeting the above attendance status criteria. It works just like I need it to. I now added a from date and to date text box so that I can check perfect attendance for each quarter. When I add the attendance date field to my query and add criteria where attendance date >= from date and <= to date the DISTINCTROW doesn't work properly. My results show the same student name repeatedly. The query itself returns the correct students though. Can I not use DISTINCTROW if I am using criteria on more than one field? By the way, I removed the attendance date field from the query and it worked correctly as it did when I originally created it so it definitely has something to do with adding attendance date to the query.

    Thanks for any help!

    Just in case it will help, here is the query.

    SELECT DISTINCTROW Student.LastName, Student.FirstName, Student.MiddleName, Student.ClassPeriod, Attendance.AttendanceDate, Attendance.AttendanceStatus FROM Student INNER JOIN Attendance ON Student.StudentID = Attendance.StudentID GROUP BY Student.LastName, Student.FirstName, Student.MiddleName, Student.ClassPeriod, Attendance.AttendanceDate, Attendance.AttendanceStatus HAVING (((Attendance.AttendanceDate)>=[forms]![PerfectAttendance]![FromDate].[Value] And (Attendance.AttendanceDate)<=[forms]![PerfectAttendance]![ToDate].[Value]) AND ((Attendance.AttendanceStatus)<>"ABSENT - EXCUSED" And (Attendance.AttendanceStatus)<>"ABSENT - UNEXCUSED" And (Attendance.AttendanceStatus)<>"TARDY - EXCUSED" And (Attendance.AttendanceStatus)<>"TARDY - UNEXCUSED" And (Attendance.AttendanceStatus)<>"REMANDED TO ALT. SCHOOL"));

  2. #2
    stmoong is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Sep 2011
    Location
    Singapore
    Posts
    108
    You should use DISTINCT instead of DISTINCTROW.

    DISTINCT will omit duplicate records based on the selected fields. DISTINCTROW will omit duplicate records based on all the fields.

    You might also want to exclude the attendance date from the selected field, but leave it as a criteria.

  3. #3
    mroberts is offline Novice
    Windows Vista Access 2007
    Join Date
    Jul 2013
    Posts
    10
    Should have mentioned that I tried DISTINCT but still showed same student more than once. I also took out the attendance status field and criteria to debug and didn't work so definitely with the attendance date portion. If I remove the attendance date field, where would I put the criteria. I am using the query builder since I'm not very experienced.

    Thanks for your assistance!

  4. #4
    mroberts is offline Novice
    Windows Vista Access 2007
    Join Date
    Jul 2013
    Posts
    10
    Got it!! Put under the or under attendance status in query builder. BTW, in my case, distinct and distinctrow worked. But now I know the diff between the two. Thanks a lot!!


    Spoke too soon. The criteria for attendance date can't be OR to the attendance status criteria. It must be AND. So I guess I will need to know where to put it.

  5. #5
    mroberts is offline Novice
    Windows Vista Access 2007
    Join Date
    Jul 2013
    Posts
    10
    This is quite weird but it is working properly now with the attendance date field and criteria there. I closed access and came back in thinking that could have been an issue but didn't help. Have no clue what fixed it. lol I'm going to compare the 2 select statements and see if there are any differences. Thanks for your help.

  6. #6
    stmoong is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Sep 2011
    Location
    Singapore
    Posts
    108
    You're welcome.

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

Similar Threads

  1. Replies: 22
    Last Post: 05-21-2013, 07:54 PM
  2. Tab Issue
    By Lazor78 in forum Forms
    Replies: 3
    Last Post: 07-05-2012, 08:18 AM
  3. VBA issue
    By manic in forum Programming
    Replies: 4
    Last Post: 02-28-2012, 03:57 PM
  4. IIF issue
    By mohiahmed in forum Queries
    Replies: 9
    Last Post: 01-22-2012, 01:06 AM
  5. Problem with Select DistinctRow
    By bgus in forum Forms
    Replies: 1
    Last Post: 04-27-2010, 03:27 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