Results 1 to 12 of 12
  1. #1
    vazdajic is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2016
    Posts
    95

    Unhappy DCOUNT with two criteria (CURRENT DATE and VALUE (from COMBOBOX) )

    Hello there..



    I would like an unbound textbox to show me the number of today's records for an user which is currently selected in a combobox: [Combo172]

    Now, with following expression (on that unbound textbox ) I see how many records 6 of us have input in the database today:

    =DCount("[CHECKED BY]", "Table","[DATECHECKED] = Date()")


    Written above works fine but I would like to see how many records I have added to the database today and if I select another user, the
    textbox should update and show me his today's records etc.

    HAVING clause is the one I have tried with but with no success..

  2. #2
    CJ_London is online now VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    modify your where parameter to something like

    "[DATECHECKED] = Date() AND user=" & me.user

    where user is the id number for the current user. if user is text then don't forget to add the single quotes

  3. #3
    vazdajic is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2016
    Posts
    95
    Hm.. I didn't defined users with primary key. Any text can be user so for me it is important to be able to use one of listed users in combobox as a criteria... I just need that text currently shown in combobox as second critecia ( first is Date() )


  4. #4
    CJ_London is online now VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    me.user would be the name of your combobox

  5. #5
    vazdajic is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2016
    Posts
    95
    I get an error

    Any new advice??

    PS: Combobox is a Text combobox: [Combo172]

  6. #6
    CJ_London is online now VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    not without knowing what you have actually used as code, what the actual error is and an example of the data being used

  7. #7
    vazdajic is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2016
    Posts
    95
    Picture tells it all. Plus, I have uploaded the database. If you have time, please take a look..
    Attached Thumbnails Attached Thumbnails DCound1.jpg  
    Attached Files Attached Files

  8. #8
    CJ_London is online now VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    you would need something like

    DCount("[CHECKED BY]", "Table","[DATECHECKED] = Date() AND [Checked By]='" & combo172 & "'")

    'Table' is probably the worst name you can use for your table name - it is a reserved word and using it can cause unexpected bugs difficult to identify. STRONGLY suggest change it to something more meaningful

    Similarly using spaces in names makes it a) easier to create a bug, b) more difficult to debug and c) when used in conjunction with a reserved word (Date in this case) can still create difficult to identify errors.

    Google 'Access reserved words' for a full list


  9. #9
    vazdajic is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2016
    Posts
    95
    In a hurry I left "Table" as a name
    I changed it now to [Table1] but second box doesnt give me nr.3 but it gives me an error (#Name?)

    Hm...

  10. #10
    CJ_London is online now VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    that means you have spelt something incorrectly - you did include the '='?

  11. #11
    vazdajic is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2016
    Posts
    95
    It works excellent:

    =DCount("[CHECKED BY]","Table1","[DATE CHECKED] = Date() AND [Checked By]='" & [combo8] & "'")

    My mistake(s)... I have had on combobox label Combo172 but it's actual name was Combo8.. Also, I have a space in [DATE CHECKED]..

    My mistakes. Your code works perfect. Many thanks!!!!!!!!!!!

  12. #12
    CJ_London is online now VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    just think how much time you would have saved if you named things properly

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

Similar Threads

  1. Replies: 7
    Last Post: 11-11-2014, 06:10 PM
  2. Dcount for 2 criteria date fields
    By rmd62163 in forum Access
    Replies: 4
    Last Post: 04-22-2014, 09:51 AM
  3. Replies: 2
    Last Post: 02-26-2014, 05:06 PM
  4. Filter Using ComboBox For Date Criteria
    By burrina in forum Forms
    Replies: 12
    Last Post: 11-29-2012, 08:02 PM
  5. query criteria for current date
    By Paul-NY in forum Queries
    Replies: 5
    Last Post: 07-05-2011, 02:21 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