count records based on date in text box

cdg

Registered User.
Local time
Today, 18:10
Joined
Apr 6, 2009
Messages
14
Hi im fairly new to Access and would like to thank any help I recieve in advance.

Here's my problem, I have an appointments database with an appointments table, the two relevant fields are ApptDate and CourtesyCar, ApptDate is a short date field and CourtesyCar is a yes/no field, this table is linked to a appointment form where each appointment shows on the form. This form has a text box that shows the date of that particular appointments page at the top, and all the appointments for that date are shown on that form so clicking a forward control moves refreshes the form with the next days date and all the appointments for that date and so on and so on, (with me so far) my problem is i have an unbound text box that i wish to show a count of all the Courtesy Cars booked out on that particular date. I have created a query that when the form is open and i click the query in the left hand pane it runs and correctly adds up all the Courtesy Cars booked on the date displayed in the forms date field, but when i make the query the data row source for the text box and open the form it doesnt open but a date parameter dialogue box opens asking for a date value, Its probably something stupid but ive pulled just about all my hair out and am now working on the cat.
this is my query
Code:
SELECT Count(tblAppointments.CourtesyCar) AS CountOfCourtesyCar, tblAppointments.ApptDate
FROM tblAppointments
GROUP BY tblAppointments.ApptDate
HAVING (((tblAppointments.ApptDate)=[Forms]![frmAppointments]![ctlViewDate]));

ctlViewDate is the date text box on the Form. Or would a Dlookup and count be a more versatile option , all i want it to do is when the form opens or is updated to display the total of all the courtesy cars booked on the date that is displayed in the text box on the form

i hope that is clearish and appreciate your time

Regards Chris
 
Try this as the control source of a textbox:

=DCount("*", "tblAppointments", "ApptDate = #" & [Forms]![frmAppointments]![ctlViewDate] & "#")
 
Thank you very much for an amazing fast result. That works perfectly, how can i get it to requery when i add or delete an appointment on the form.

Thanks again for your help (cats hair is safe again now)


Cheers Chris
 
Nobody wants to see a hairless cat! Basically:

Me.TextBoxName.Requery

Access is very "event driven", so the trick is to find the events being triggered so you can put the code there. It sounds like the After Insert and After Delete Confirm events are the ones you want.
 
Thanks again for your help i'll find where these events are and paste that code.

Cheers Chris
 
No problem; post back if you get stuck. Welcome to the site by the way.
 

Users who are viewing this thread

Back
Top Bottom