Results 1 to 6 of 6
  1. #1
    Gina Maylone is offline Always learning
    Windows 10 Access 2016
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544

    Date serial criteria giving me wrong data

    Hello all! And Happy Friday! I hope ya'll are somewhere warm and snow free because I am NOT. Anyway Access is doing its best to blow my mind again. I am creating statements where the first line is the balance forward (anything that happened previous to the current month.
    Code:
    SELECT Accounts.MemberID_FK, Sum((Nz([dbamount],0)-Nz([cramount],0))) AS BALFWD, Sum(Accounts.CRAmount) AS SumOfCRAmount, Sum(Accounts.DBAmount) AS SumOfDBAmount, Accounts.CRDATE, Accounts.Details, Accounts.Comments, Accounts.DBDate, Accounts.AsmtType
    FROM Accounts
    GROUP BY Accounts.MemberID_FK, Accounts.CRDATE, Accounts.Details, Accounts.Comments, Accounts.DBDate, Accounts.AsmtType
    HAVING (((Sum((Nz([dbamount],0)-Nz([cramount],0))))<>0) AND ((Accounts.DBDate)<=DateSerial(Year([Forms]![runassessments]![DateRun]),Month([Forms]![runassessments]![DateRun]),1)) AND ((Accounts.AsmtType) Like [Forms]![RunAssessments]![AssessmentType] & "*")) OR (((Sum((Nz([dbamount],0)-Nz([cramount],0))))<>0) AND ((Accounts.CRDATE)<=DateSerial(Year([Forms]![runassessments]![DateRun]),Month([Forms]![runassessments]![DateRun]),1)) AND ((Accounts.AsmtType) Like [Forms]![RunAssessments]![AssessmentType] & "*"));
    My daterun is 2/28/19. It is including a transaction posted on 2/1/2019 (an accounts.dbdate)! Even if I hard enter the date I get 2/1/19 included.
    Code:
    SELECT Accounts.MemberID_FK, Sum((Nz([dbamount],0)-Nz([cramount],0))) AS BALFWD, Sum(Accounts.CRAmount) AS SumOfCRAmount, Sum(Accounts.DBAmount) AS SumOfDBAmount, Accounts.CRDATE, Accounts.Details, Accounts.Comments, Accounts.DBDate, Accounts.AsmtType
    FROM Accounts
    GROUP BY Accounts.MemberID_FK, Accounts.CRDATE, Accounts.Details, Accounts.Comments, Accounts.DBDate, Accounts.AsmtType
    HAVING (((Accounts.MemberID_FK)=1394) AND ((Sum((Nz([dbamount],0)-Nz([cramount],0))))<>0) AND (
    Code:
    (Accounts.DBDate)<=DateSerial(Year(#2/28/2019#),Month(#2/28/2019#),1)
    ) AND ((Accounts.AsmtType) Like [Forms]![RunAssessments]![AssessmentType] & "*")) OR (((Accounts.MemberID_FK)=1394) AND ((Sum((Nz([dbamount],0)-Nz([cramount],0))))<>0) AND ((Accounts.CRDATE)<=DateSerial(Year(#2/28/2019#),Month(#2/28/2019#),1)) AND ((Accounts.AsmtType) Like [Forms]![RunAssessments]![AssessmentType] & "*"));
    Anyone have any thoughts? The fields are formatted short date in the table and query. In case it matters, Access 16, Windows 10. Thanks!!

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    I see no need to use DATESERIAL,
    can you not just use BETWEEEN date1 AND date2?

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Your criteria is "<=", and 2/1 is "less than or equal to" 2/1. Am I missing something?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    Gina Maylone is offline Always learning
    Windows 10 Access 2016
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544
    I just figured it out, duh. Thanks Paul. Needed another set of eyes. :-)

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    No problem, we've all been in that boat.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    Gina Maylone is offline Always learning
    Windows 10 Access 2016
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544
    Because date1 can be infinite. Some people owe on their accounts back to 2016. So it's better to leave it open ended. Thanks ranman!

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

Similar Threads

  1. Docmd.OutPutTo giving me the wrong data
    By jwill in forum Programming
    Replies: 5
    Last Post: 07-22-2014, 02:26 PM
  2. Summing Time is giving me wrong totals.
    By Nuke1096 in forum Access
    Replies: 7
    Last Post: 06-13-2013, 11:00 AM
  3. Calculation in Query giving wrong results
    By dargo72 in forum Queries
    Replies: 11
    Last Post: 11-07-2012, 05:39 AM
  4. Access giving wrong result using sql query
    By amlanroy in forum Access
    Replies: 3
    Last Post: 05-10-2012, 10:11 AM
  5. Title: Giving Wrong Name
    By netchie in forum Forms
    Replies: 5
    Last Post: 09-15-2011, 10:53 AM

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