Results 1 to 10 of 10
  1. #1
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496

    Can't get one date result - trying this code

    I have a form which opens a report and displays all schools that have a date field filled with dates between dates on unbound text boxes on a form.

    I also have a dcount which should pull the same results as the report and count them

    =DCount("NewSchoolsID","tblSchools",Not IsNull([CatalogueLabelPrinted]) And "CatalogueLabelPrinted >= #" & [BeforeDate] & "# and <= #" & [AfterDate] & "#")



    I tried "between" but that didn't work for dates between current/picked same date and current/picked same date

    I get 0 instead of the count that the report has made so I tried >= but I get too many results.

    The idea is that the field has to be not null and within the date period on the form. Any suggestions?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,962
    Try:

    =DCount("NewSchoolsID", "tblSchools", "Not IsNull([CatalogueLabelPrinted]) And CatalogueLabelPrinted Between #" & [BeforeDate] & "# And #" & [AfterDate] & "#")

    or

    =DCount("NewSchoolsID", "tblSchools", "Not IsNull([CatalogueLabelPrinted]) And CatalogueLabelPrinted >=" & [BeforeDate] & "# And CatalogueLabelPrinted <= #" & [AfterDate] & "#")
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by June7 View Post
    Try:

    =DCount("NewSchoolsID", "tblSchools", "Not IsNull([CatalogueLabelPrinted]) And CatalogueLabelPrinted Between #" & [BeforeDate] & "# And #" & [AfterDate] & "#")

    or

    =DCount("NewSchoolsID", "tblSchools", "Not IsNull([CatalogueLabelPrinted]) And CatalogueLabelPrinted >=" & [BeforeDate] & "# And CatalogueLabelPrinted <= #" & [AfterDate] & "#")
    I used
    Code:
    =DCount("NewSchoolsID","tblSchools","Not IsNull([CatalogueLabelPrinted]) And CatalogueLabelPrinted >=#" & [BeforeDate] & "# And CatalogueLabelPrinted <= #" & [AfterDate] & "#")
    However I get 0

  4. #4
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Attachment 14305

    how the report works

  5. #5
    amrut is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    Dubai
    Posts
    614
    Does this works ?
    Code:
    =DCount("NewSchoolsID","tblSchools","Not IsNull([CatalogueLabelPrinted]) And CatalogueLabelPrinted >=#" & Format([BeforeDate],"mm\/dd\/yyyy") & "# And CatalogueLabelPrinted <= #" & Format([AfterDate],"mm\/dd\/yyyy") & "#")

  6. #6
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by amrut View Post
    Does this works ?
    Code:
    =DCount("NewSchoolsID","tblSchools","Not IsNull([CatalogueLabelPrinted]) And CatalogueLabelPrinted >=#" & Format([BeforeDate],"mm\/dd\/yyyy") & "# And CatalogueLabelPrinted <= #" & Format([AfterDate],"mm\/dd\/yyyy") & "#")
    I'm not sure why and how formatting the date fields would work, can you explain why? I'll give it a go either way.

  7. #7
    amrut is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    Dubai
    Posts
    614
    I am always used to follow dd/mm/yyyy format. While working on my first database, in case of VBA for forms and expressions in text boxes , the aggregate functions returned wrong results. Formatting them in the way shown, yielded correct results.
    Quote from http://allenbrowne.com/ser-36.html. :
    Regardless or your regional settings, Access expects these literal dates to be in the American format, e.g. #12/31/1999#.

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,962
    I get 'invalid attachment' error on your attachment link.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    lfpm062010 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Location
    US
    Posts
    415
    Is the field [CatalogueLabelPrinted] contains date and time?

    If you have time stamp then looking for [BeforeDate] and [AfterDate] with the same value will not return any result. For example: [BeforeDate] and [AfterDate] both equal #10/01/2013# 'MM/DD/YYYY
    To get result with time stamp then you have to use [BeforeDate] = #10/01/2013 00:00:00# and [AfterDate] = #10/01/2013 23:59:59#.

  10. #10
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by amrut View Post
    I am always used to follow dd/mm/yyyy format. While working on my first database, in case of VBA for forms and expressions in text boxes , the aggregate functions returned wrong results. Formatting them in the way shown, yielded correct results.
    Quote from http://allenbrowne.com/ser-36.html. :
    Regardless or your regional settings, Access expects these literal dates to be in the American format, e.g. #12/31/1999#.
    Interesting. That fixed the problem! will have to be aware of that in the future!!

    Thank you all for the help!

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

Similar Threads

  1. convert result of date claculation to number
    By survivo01 in forum Queries
    Replies: 1
    Last Post: 08-12-2013, 02:46 PM
  2. how can i switch this code to make a excel result?
    By richthekid in forum Import/Export Data
    Replies: 1
    Last Post: 07-25-2013, 09:16 PM
  3. Write code to see all date between two date
    By barkarlo in forum Programming
    Replies: 2
    Last Post: 02-24-2013, 10:58 AM
  4. Replies: 2
    Last Post: 09-18-2011, 03:45 AM
  5. Return DLookup result as date?
    By kman42 in forum Access
    Replies: 8
    Last Post: 04-22-2011, 11:35 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