Hi,
I am very new to using Access and databases in general. I have been playing around to try to gain an understanding but there are huge gaps in my knowledge.
I would like to use DCount to count the number of records with a particular value in one of the fields of one of my tables. I looked at the syntax for DCount and it all seemed straightforward.
I am trying create this counter on a form. I have created a form ("form2020Events") which corresponds to my "2020Events" table. I would like the form to display a counter of all bookings made for that event. (I also have a "2020Bookings" table). When I try to use the following control source for the text box on my form I get a #Name? error:
=DCount("*","2020Bookings", "Event='Party'")
When I use:
=DCount("*","2020Bookings")
I get a count of all the records in 2020Bookings.
Could this be because the "Event" field in 2020Bookings is a lookup field (to the "2020Events" table)? I thought this might be the case so I changed the condition to equal the ID instead (='Party' to ='1'), the Event ID but that still didn't solve the issue.
So I tried on a new database replicating this and found I could create a counter if the lookup wasn't in place (ie the Event field was manually entered as text rather than looked up from the 2020Events table). However, by doing this I have introduced the possibility of making a typo when manually entering the Event to a new booking, instead of selecting from only the events stored in the table "2020Events".
I then tried solving the problem by creating the Event field in "2020Bookings" with data type = Short Text (instead of a lookup). Then in the corresponding form for adding new bookings to the table, I created a Combo Box to lookup the "Event". I.e. creating the lookup on the form rather than in the table. That didn't help either.
At this point my brain was completely befuddled and loosing all grip on the changes I have made...
More generically, what I am asking is what is the best way to create a counter on a form, to calculate the number of records with a specific field value in a table, when those entries are created using a lookup to a table? And if the lookup is the problem, what is the best way to set up the entries into that field such that they are limited to the entries defined in another table?
Hope that made some sense...
I have done a lot of "googling" and scouring forums for something to help but I haven't found a solution.
Thanks in advance for any help given.