display the count of 'today occurences' from a table in a form?

hiccup

Registered User.
Local time
Today, 09:49
Joined
Apr 4, 2015
Messages
25
Thanks to the support in this forum I am close to finalizing my first database project. For now I have one more question: My database contains a table that has two fields named 'occurance1' and 'occurance2', both containing a range of different dates. In a form I have in that database, I would like to have a field displaying the total counts for both 'occurance1' and 'occurance2', but only the count for both occurances that have 'Today' as a date. Preferably without having to run yet another query, so if possible I would like that as soon as an occurance that has 'today' as a date is entered in the table, the total count shows correctly in the form. I hope I make any sense, and somebody can help me how to accomplish this?
 
Maybe pictures make it more clear what I want to achieve?
The first picture would be the table, the second picture is what I would like to have displayed in my form.
 

Attachments

  • Occurances.PNG
    Occurances.PNG
    7.2 KB · Views: 87
  • Occurrances2.PNG
    Occurrances2.PNG
    1.7 KB · Views: 79
Ok, thnx plog! I am going to explore that tomorrow.
 
Hm, I really feel like a chimp with a calculator.

I have no understanding of codes in Access, and after some Googling I am assuming I must do the following:
- create a Text box in my form
- open the property sheet for that box
- go to the 'data' tab
- on the right of 'Control Source' enter: =DCount("field-name","table-name",[Date()])

As I understand that should count all 'today' dates present in that specific field column?
But if I do that, I get an error: 'invalid syntax'.
What am I doing wrong here?
 
Not bad, 90% there. The criteria argument of your DCount is incorrect.

[Date()]

First, it needs to be a string, your's is techincally a reference to a field. Second, it needs to be a statement that evaluates to True/False, which usually means you need some sort of comparison operator (=, >, <).

You need to compare whatever field holds the date value to the current date. Your criteria argument should look something like this:

"[YourDateFieldName]=#" & Date() & "#"
 
Chimp's back again:

I zipped and attached a simple database containing only this challenge.
When I enter your suggestion:
=DCount("Dates1","tbl_Occurrences","[Dates1]=#" & Date() & "#" )
I still get a syntax error?
 

Attachments

That code works for me. Were exactly are you putting it? It should go in the Control Source of the CountToday control.
 
At least the Chimp can upload a screenshot ;-)
 

Attachments

  • SyntaxError.png
    SyntaxError.png
    81.7 KB · Views: 91
Weird, I'm using exact same code in your database and it works fine. Try this:

Put brackets around Date1 in the first argument:

=DCount("[Dates1]","tbl_Occurrences","[Dates1]=#" & Date() & "#" )

If that doesn't work, see if this will work:

=DCount("[Dates1]","tbl_Occurrences")

If that works, it means the criteria is the culprit.
 
Found it!
It was due to the fact my regional settings differ. I changed the"," to ";", and now your formula works like a charm.

Thanks plog!
 

Users who are viewing this thread

Back
Top Bottom