Results 1 to 12 of 12
  1. #1
    marcossch is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2019
    Posts
    6

    How to calculate total records with same hour?

    I am struggling days to solve this. A have to show in a form, how many clients (records) are scheduled at the same date and time. I tried to use =DCount("*";"Agenda";" [Hour] = " & [Hour] & "") with no success.



    Thanks for any help!

    Click image for larger version. 

Name:	access.jpg 
Views:	23 
Size:	238.3 KB 
ID:	40184

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725
    What is the datatype of field Hour in your table?
    Can you show your Hour table design and a few records?

  3. #3
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    What is the datatype of field Hour in your table?
    I'll bet your money that it is text (care to guess why?).
    In which case, maybe
    DCount("*";"Agenda";"[Hour] = '" & [Hour] & "'")
    But getting an answer to your question would be good.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    I suspect that you're right! The Combobox for hours probably has a Value List as its Row Source Type...which I believe would make the value Text.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  5. #5
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    I'm going by what I can see, not by what I can't. But that's a good guess.

  6. #6
    marcossch is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2019
    Posts
    6
    Quote Originally Posted by orange View Post
    What is the datatype of field Hour in your table?
    Can you show your Hour table design and a few records?
    For sure. I am not an expert and may be doing some huge mistake.
    Click image for larger version. 

Name:	Agenda-data.jpg 
Views:	10 
Size:	194.6 KB 
ID:	40207
    Click image for larger version. 

Name:	Agenda-design.jpg 
Views:	10 
Size:	236.8 KB 
ID:	40208
    Click image for larger version. 

Name:	hour-data.jpg 
Views:	10 
Size:	40.5 KB 
ID:	40209
    Click image for larger version. 

Name:	hour-design.jpg 
Views:	10 
Size:	18.0 KB 
ID:	40210

  7. #7
    marcossch is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2019
    Posts
    6
    Couldn´t discover where is the delete post.... got duplicated.

  8. #8
    marcossch is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2019
    Posts
    6
    Micron genius!. DCount("*";"Agenda";"[Hour] = '" & [Hour] & "'")
    As text it gives me a number, but I guess it is counting for every day. How could I count only the same day and same hour?
    Click image for larger version. 

Name:	access.jpg 
Views:	10 
Size:	246.5 KB 
ID:	40211

  9. #9
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    I think my suggestion in my first post applies. Spaced out to see the difference more clearly: " DCount("*";"Agenda"; ' " [Hour] = " & [Hour] & " ' ")
    I think the major mistake is that a time field should be Date/Time data type and not text.

    In case anyone is wondering, the clues were the left justification of the hour values (by default, text is left, numbers are right). I discounted the possibility that OP would be justifying this field manually. Plus, the DCount expression is trying to add a zls.

  10. #10
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    I see our posts crossed. Try adding the date as criteria as well as the hour. Maybe
    DCount("*";"Agenda";" "[Data] = #DateHere# And [Hour] = '" & [Hour] & "'")

    I'm a bit confused as to why it works properly (if it does) when your field is named Horario but you use Hour. Also, Data is a reserved word. I wonder what the implications are when other languages are involved. Or does Data not translate to Date?
    Last edited by Micron; 11-18-2019 at 10:18 AM. Reason: added comment

  11. #11
    marcossch is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2019
    Posts
    6
    Quote Originally Posted by Micron View Post
    I see our posts crossed. Try adding the date as criteria as well as the hour. Maybe
    DCount("*";"Agenda";" "[Data] = #DateHere# And [Hour] = '" & [Hour] & "'")

    I'm a bit confused as to why it works properly (if it does) when your field is named Horario but you use Hour. Also, Data is a reserved word. I wonder what the implications are when other languages are involved. Or does Data not translate to Date?

    =DCount("*";"Agenda";"[Data] = #" & [Data] & "# AND [Horário] = '" & [Horário] & "'") solved the problem!!!!!!
    I just translated in the first post Horário to hour to keep the forum language, but I had to use Horário in order to work.
    Perfect solution. Thanks a lot.
    I think Access could give us a hint other than just ?ERROR and nothing else.

  12. #12
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    I think Access could give us a hint other than just ?ERROR and nothing else.
    I understand why you say that, but the problem is that those types of messages can only be generic because of the vast multitude of reasons that cause them. It could be
    - a missing ' or " or [ or ( or ] or )
    - a misspelled control name
    - a mispelled field name
    - improper use of an operator; e.g. LIKE, >, =, etc.
    - improper reference to a main form, subform or one of its fields/controls
    - where you use a domain aggregate function (e.g. DSum) in an expression where the field and form control have the same name
    - etc.
    I guess at least they try to narrow down the reasons by distinguishing between #Name and #Error. There may be others that I can't think of right now.

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

Similar Threads

  1. total calls per hour
    By desireemm1 in forum Reports
    Replies: 11
    Last Post: 10-28-2014, 03:29 PM
  2. Replies: 4
    Last Post: 10-10-2014, 02:39 PM
  3. Replies: 1
    Last Post: 10-20-2013, 10:04 AM
  4. How to Calculate this Grand Total
    By TWD in forum Reports
    Replies: 2
    Last Post: 01-13-2012, 11:36 AM
  5. Replies: 2
    Last Post: 03-02-2011, 01:43 PM

Tags for this Thread

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