Results 1 to 5 of 5
  1. #1
    jj1 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2014
    Posts
    128

    Unhappy Query Generating different results

    If I use this query I get the results what I want
    SELECT tblMainTWTTPSheet.txtRootCause, Count(tblMainTWTTPSheet.txtRootCause) AS CountOftxtRootCause

    FROM tblMainTWTTPSheet
    GROUP BY tblMainTWTTPSheet.txtRootCause
    HAVING (((tblMainTWTTPSheet.txtRootCause) Is Not Null) AND ((Count(tblMainTWTTPSheet.txtRootCause)) Is Not Null))


    ORDER BY Count(tblMainTWTTPSheet.txtRootCause) DESC;

    But What I am trying to do is on a form select dates and generate data in this query. which doesnot happen even if I use the following query. Can anybody help me what wrong I am doing.

    SELECT tblMainTWTTPSheet.txtRootCause, Count(tblMainTWTTPSheet.txtRootCause) AS CountOftxtRootCause

    FROM tblMainTWTTPSheet
    WHERE (((tblMainTWTTPSheet.date) Between [Forms]![frmStratificationOfRootCauses]![startDate] And [Forms]![frmStratificationOfRootCauses]![endDate]))
    GROUP BY tblMainTWTTPSheet.txtRootCause
    HAVING (((tblMainTWTTPSheet.txtRootCause) Is Not Null) AND ((Count(tblMainTWTTPSheet.txtRootCause)) Is Not Null));

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    Your first query isn't checking the date at all so how is it giving you the results you want if you want to apply date criteria to your query? Nor is the query ordered the same way.

    Are you sure your fields on your form as in a date format? Are you generating this SQL statement dynamically or do you actually have a saved query? Are you sure the 'date' field in your table tblMainTWTTPSheet is being stored as a date and not as a text value?

    I suspect there is a disconnect between how the date value is being stored and the date criteria (by the way it's poor practice to use reserved words for field names like 'date', 'year', 'month', 'control', etc).

    you may be able to try criteria like


    between "#" & forms!frmstratificationofrootcauses!startdate 7 "#" and "#" & forms!frmstratificationofrootcauses!enddate & "#"

    This would force your start date and end date to be considered dates if they are currently being considered strings

  3. #3
    jj1 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2014
    Posts
    128
    Its didn't solve my problem. It has date as date/time field in my main table.

    between "#" & forms!frmstratificationofrootcauses!startdate 7 "#" and "#" & forms!frmstratificationofrootcauses!enddate & "#" gives error query is complex to be evaluated.





    Quote Originally Posted by rpeare View Post
    Your first query isn't checking the date at all so how is it giving you the results you want if you want to apply date criteria to your query? Nor is the query ordered the same way.

    Are you sure your fields on your form as in a date format? Are you generating this SQL statement dynamically or do you actually have a saved query? Are you sure the 'date' field in your table tblMainTWTTPSheet is being stored as a date and not as a text value?

    I suspect there is a disconnect between how the date value is being stored and the date criteria (by the way it's poor practice to use reserved words for field names like 'date', 'year', 'month', 'control', etc).

    you may be able to try criteria like


    between "#" & forms!frmstratificationofrootcauses!startdate 7 "#" and "#" & forms!frmstratificationofrootcauses!enddate & "#"

    This would force your start date and end date to be considered dates if they are currently being considered strings

  4. #4
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    If you cut and paste that you have a 7 where there should be an & mark right after the startdate

  5. #5
    jj1 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2014
    Posts
    128
    Ya I figured that out

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

Similar Threads

  1. Replies: 4
    Last Post: 08-21-2013, 08:20 AM
  2. Replies: 5
    Last Post: 05-21-2013, 02:21 PM
  3. Replies: 3
    Last Post: 05-02-2013, 10:36 AM
  4. Replies: 6
    Last Post: 05-14-2012, 07:24 AM
  5. Replies: 3
    Last Post: 03-28-2012, 06:00 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