Question DCount in textbox on form with dates (1 Viewer)

ccondran08

Registered User.
Local time
Today, 16:20
Joined
Feb 27, 2014
Messages
58
I have the following DCount formula in a text box on the main menu form (frm_Main_Menu) which works fine. However, there is a field in the query called "Date_Planned" and I have two text boxes called txt_Start_Date and txt_End_Date which is also on the main menu. I would to add to the formula below to count the records if the 'Date_Planned' is between the txt_Start_Date and txt_End_Date. I have tried a few ways but still cannot get it to work. Any help would be greatly appreciated. :banghead:


=DCount("[Project_ID]","qry_Audit_Plan_Dates_PM_Handover","[tbl_LOB].[Advisor]=[Forms]![frm_Main_Menu]![cbo_Advisor] And [Audit_Type] = '2 - PM Handover' And [Planned] = -1")
 

isladogs

MVP / VIP
Local time
Today, 09:20
Joined
Jan 14, 2017
Messages
18,219
If you are based in the USA, then

Code:
=DCount("[Project_ID]","qry_Audit_Plan_Dates_PM_Handover","[tbl_LOB].[Advisor]=[Forms]![frm_Main_Menu]![cbo_Advisor] And [Audit_Type] = '2 - PM Handover' And [Planned] = -1 And [Date_Planned] Between #" & Me.txtStartDate & "# And #" & Me.txtEndDate & "#")

If not, you will need to format the dates to mm/dd/yyyy format:

Code:
=DCount("[Project_ID]","qry_Audit_Plan_Dates_PM_Handover","[tbl_LOB].[Advisor]=[Forms]![frm_Main_Menu]![cbo_Advisor] And [Audit_Type] = '2 - PM Handover' And [Planned] = -1 And [Date_Planned] Between #" & Format(Me.txtStartDate,"mm/dd/yyyy") & "# And #" & Format(Me.txtEndDate,"mm/dd/yyyy") & "#")

This assumes the original formula works as I've not checked that bit
 
Last edited:

Users who are viewing this thread

Top Bottom