Results 1 to 15 of 15
  1. #1
    Shaima is offline Novice
    Windows 10 Access 2019
    Join Date
    Oct 2022
    Posts
    7

    Access date range quary

    Hi guys..
    I have a problem in Dcount function.. when i enter a date it didn't count correctly.. it take all the records of all the years.. and i want only the records that mentioned.. before that it was work correctly..
    What is the wrong in this code
    Dcount ("[Bill_no_BDM]","BillDataMov","[Isu_Kind_BDM]='not taken' And [zone_BDM]='" & [zone_BDM] & "'")

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    If the second field is a date field you need # as the delimiter:

    http://www.theaccessweb.com/general/gen0018.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Shaima is offline Novice
    Windows 10 Access 2019
    Join Date
    Oct 2022
    Posts
    7
    Hi..
    No the second field is not date it is a zone name... I make a quary for the date... And i create a report to count the number of records a according to the bill that the items didn't token and the zone name.. write this code in the builder..
    This code was working before... But now i don't know where is the problem.. when i run this code it appear the number of records correctly but the result number is wrong... It appear to me the number of all records for all yeas it didn't filter the year correctly..

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    The query didn't, or the DCount()? Is BillDataMov the query?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,574
    Well the problem is with your query not the DCount() ?
    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

  6. #6
    Shaima is offline Novice
    Windows 10 Access 2019
    Join Date
    Oct 2022
    Posts
    7
    The Dcount didn't get the correct result...
    I have a report and i have a quary..
    The quary specified the range of the date and the zone name and also the token items from the store.. The items that appear in the report using the quary is correct.. the quary is working correctly in the report..

    I used Dcount function to count the number of the records that appear in the report but the total items in the report is getting wrong.. i want to count the number of items that appear in the report.. but it count the number of records wrong.. it get the result of all items in all years that in the table.. it didn't count the result of the year that spcified in the quary..

    BillDataMov is the name of the table...

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,574
    If you want to count the number of items in the report, just add a count() in the report.

    If Access is giving you the wrong count, then your criteria is wrong. Plain and simple.

    Can you upload the DB with enough data to show the problem?

    Use the name of the query for the domain in the DCount() if you insist on using it?

    How can you expect the table to provide the same as your query when your query has criteria for a certain year? The DCount() would need the same criteria?

    Like comparing apples and oranges?
    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

  8. #8
    Shaima is offline Novice
    Windows 10 Access 2019
    Join Date
    Oct 2022
    Posts
    7
    How can i upload a DB or even photo to explain the issue?! I don't know from where can i upload data

  9. #9
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,574
    Quote Originally Posted by Shaima View Post
    How can i upload a DB or even photo to explain the issue?! I don't know from where can i upload data
    See the top of the screen.
    However I think I understand your problem now. The query is restricted by year, the Dcount() is not. Make them have the same criteria.
    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

  10. #10
    Shaima is offline Novice
    Windows 10 Access 2019
    Join Date
    Oct 2022
    Posts
    7
    Click image for larger version. 

Name:	1.jpg 
Views:	19 
Size:	135.4 KB 
ID:	49025Click image for larger version. 

Name:	3.jpg 
Views:	19 
Size:	95.8 KB 
ID:	49026Click image for larger version. 

Name:	2.jpg 
Views:	19 
Size:	184.8 KB 
ID:	49027

    pic. 1. is the report that contain the items in details, the total number of item, zone name and date range.. see the total number of items is not match with the records.. the items details is correct with the date range.. but the total result is not match.. when i check the table and do filter by (zone name) and (item not token form the store) it get all the records for all years in the table and appear the result (116) records.. it didn't take the correct date range that i specified on top witch is 8 records only... so i recognize that it take all the records for all years that in the table.. it didn't filter by date range..

    pic. 2. is the query for date range, zone name and item not token from store..

    pic. 3. is code builder of Dcount to count the total number of records..

    where is the problem?

  11. #11
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,574
    The problem is the criteria is NOT THE SAME!!!! I do not know how else to say it?

    The Dcount() does NOT take into account *ANY* date whatsoever? What part of that do you not understand.?

    The easiest way out of this fiasco is to use your query for the domain in DCount(). Then it looks like you would not need any criteria at all? The criteria is all in the query?

    Test it out in the immediate window. That would be what I would do.

    If you just want a count in the report then I would just use the report Count(). Even easier.
    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

  12. #12
    Shaima is offline Novice
    Windows 10 Access 2019
    Join Date
    Oct 2022
    Posts
    7
    You mean that i use Dcount criteria in the query... So where i write Dcount criteria in which column... If i use criteria in the query is the total result of records will shown in the report or not..
    Thank you..

  13. #13
    Shaima is offline Novice
    Windows 10 Access 2019
    Join Date
    Oct 2022
    Posts
    7
    Hi everyone...
    I tried to write the criteria in the query... but the result is same.. where in the report.. Dcount result is same 116.. it seems that Dcount function is wrong.. any one can help please..

  14. #14
    CarlettoFed is offline Competent Performer
    Windows 7 64bit Access 2013 32bit
    Join Date
    Dec 2019
    Posts
    274
    In the control at the bottom of the report, where there is the formula = DCount (...), you have to write = Count (Autonumber)

  15. #15
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,574
    DCount() function is never wrong.
    You are just using it incorrectly.

    Just change the table name in the function to your quey name. Do not put the function as a new field. That is not going to change anything. Why would you think it would?
    Report count is still the way I would go.
    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

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

Similar Threads

  1. Replies: 17
    Last Post: 07-31-2018, 01:23 PM
  2. Replies: 3
    Last Post: 02-02-2016, 11:03 AM
  3. Replies: 3
    Last Post: 01-26-2016, 01:56 PM
  4. quary addition subtraction
    By agyapong isaac in forum Queries
    Replies: 2
    Last Post: 12-28-2012, 12:07 PM
  5. Replies: 7
    Last Post: 12-06-2012, 03:10 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