Results 1 to 3 of 3
  1. #1
    deda is offline Novice
    Windows 10 Office 365
    Join Date
    Aug 2022
    Posts
    3

    Deciphering a DCount function

    I have a snipped of VBA that I'm a little confused over
    Code:
    Me.TxtToDo = DCount("action", "tbl_To Do", "who like '" & GetUserName() & "*'" & " and x=" & 0 & " and [date] <#" & Date & "#") & " overdue" & " | " & _DCount("action", "tbl_To Do", "who like '" & GetUserName() & "*'" & " and x=" & 0 & " and [date] =#" & Date & "#") & " due today" & " | " & DCount( _
    "action", "tbl_To Do", "who like '" & GetUserName() & "*'" & " and x=" & 0 & " and [date] >#" & Date & "#") & " future tasks"
    I'm only looking for the overdue function, so I'm pretty sure that part is
    Code:
    DCount("action", "tbl_To Do", "who like '" & GetUserName() & "*'" & " and x=" & 0 & " and [date] <#" & Date & "#") & " overdue
    . I looked up the documentation for the DCount function, so I know that it's pulling data from the tbh_To Do, however I'm really confused on the third parameter. I'm not sure what the strings are doing, and the "#", so I was wondering if someone could help me figure out what this function is doing. Thanks



    (The reason I'm looking at the overdue part is because it is displaying more overdue tasks than there actually is)

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    The # character is a date/time delimiter. It defines the date/time input to differentiate from rest of constructed string of characters.

    Parameter for text type field needs apostrophe (or doubled quote marks) as delimiter. Number type field does not require delimiter.
    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
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    suspect your issue is date formatting. By having Date as a separate text value (you are passing it into a string), it needs to be formatted US style of mm/dd/yyyy or database standard of yyyy-mm-dd.

    So my guess is you do not use the US style but dd/mm/yyyy. This means that if the date is 10th June you will have 10/06/2022 - which in US style will be interpreted as 6th October.

    The code has not been written very well and can be simplified to

    Code:
    Me.TxtToDo = DCount("action", "tbl_To Do", "who like '" & GetUserName() & "*' and x=0 and [date] < Date()") & " overdue"
    really not a good idea to have fields with the same name as functions

    and not sure why you are using username* - surely if your username is Rob, you don't also want user Robert, user Robina as well? So would think

    Code:
    Me.TxtToDo = DCount("action", "tbl_To Do", "who = '" & GetUserName() & "' and x=0 and [date] < Date()") & " overdue"

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

Similar Threads

  1. deciphering errors on a double-joined query
    By hammerman in forum Queries
    Replies: 7
    Last Post: 01-31-2018, 06:18 PM
  2. Dcount Function
    By felixkiprono402@gmail.com in forum Access
    Replies: 10
    Last Post: 05-23-2017, 09:26 AM
  3. Help with DCOUNT Function in Module
    By qcjustin in forum Access
    Replies: 9
    Last Post: 04-08-2015, 09:54 AM
  4. DCOUNT function with IN statement
    By dwilson in forum Access
    Replies: 2
    Last Post: 08-12-2011, 09:54 AM
  5. DCount function problem
    By 10 Gauge in forum Forms
    Replies: 5
    Last Post: 02-28-2011, 02:08 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