Avatar of pdvsa
pdvsa
Flag for United States of America asked on

Day Count - User Input

Experts, I have a query that shows a day count between 2 dates ([ValueDate]) with condition Where T.FacilityType=Q_Disbursement.FacilityType",
How can I modify the below to prompt user to enter a date which the last record date range extends to?  

Example, in the below pic, you can see that for the next to last record in JBIC, the date is February 29, 2016 and the day count is 70 (Feb 29 to May 9) but what I need is a msgbox that pops up and asks the user to enter a date.  If that date, for example, was May 10, 2016 and not May 9 as shown in the pic, the day count would be 71 (Feb 29 to May 10).  User would enter in a date much later than that though.  My example is for simplicity.  

I hope that makes sense.  It likely doesnt so please ask me if need.

attached a db with Q_DisbursementSum.

here is the sql though:
SELECT Q_Disbursement.FacilityType, Q_Disbursement.ValueDate, Q_Disbursement.FacilityAmount, Q_Disbursement.Amount, (Select Sum(T.Amount) From Q_Disbursement As T Where T.FacilityType=Q_Disbursement.FacilityType And T.ValueDate <= Q_Disbursement.ValueDate) AS [Cumulative Drawn], [FacilityAmount]-[Cumulative Drawn] AS Available, DateDiff("d",[ValueDate],(Select Min(Q.ValueDate) From Q_Disbursement As Q Where Q.FacilityType = Q_Disbursement.FacilityType And Q.ValueDate > Q_Disbursement.ValueDate)) AS DayCountx
FROM Q_Disbursement
GROUP BY Q_Disbursement.FacilityType, Q_Disbursement.ValueDate, Q_Disbursement.FacilityAmount, Q_Disbursement.Amount, Q_Disbursement.FacilityAmount
ORDER BY Q_Disbursement.FacilityType, Q_Disbursement.ValueDate;

Open in new window



screeshot of query:
daycountBalanceEE.accdb
Microsoft Access

Avatar of undefined
Last Comment
Gustav Brock

8/22/2022 - Mon
crystal (strive4peace) - Microsoft MVP, Access

create a parameter by using something like: [enter the last record date :] and using it where you want the value substituted. Be sure to write it exactly the same each time (copy and paste to avoid typing mistakes)

Define this parameter to be a date by choosing Parameters from the Design ribbon tab (Query Tools) and choosing the data type query Parameter DataType
Gustav Brock

This query will (maybe) do that - if I understand your question:
SELECT Q_Disbursement.FacilityType, Q_Disbursement.ValueDate, Q_Disbursement.FacilityAmount, Q_Disbursement.Amount, (Select Sum(T.Amount) From Q_Disbursement As T Where T.FacilityType=Q_Disbursement.FacilityType And T.ValueDate <= Q_Disbursement.ValueDate) AS [Cumulative Drawn], [FacilityAmount]-[Cumulative Drawn] AS Available, DateDiff("d",[ValueDate],(Select Min(IIf([Enter Last Date:]>Q.[ValueDate],[Enter Last Date:],Q.[ValueDate])) From Q_Disbursement As Q Where Q.FacilityType = Q_Disbursement.FacilityType And Q.ValueDate > Q_Disbursement.ValueDate)) AS DayCountx
FROM Q_Disbursement
GROUP BY Q_Disbursement.FacilityType, Q_Disbursement.ValueDate, Q_Disbursement.FacilityAmount, Q_Disbursement.Amount, Q_Disbursement.FacilityAmount
ORDER BY Q_Disbursement.FacilityType, Q_Disbursement.ValueDate;

Open in new window

ee2.PNG/gustav
pdvsa

ASKER
Hi Gustav,

thank you for the response. I do see that the record with 70 days did change to 71 however the lines above changed as well but those should actually remain as is. I failed to mention that criteria.  Sorry about that.  The only record that should change is the record with 70 days (but noting the where condition Where T.FacilityType=Q_Disbursement.FacilityType) and not the other records above as those should still be calculated based on the [ValueDAte] and not the pop up msg box prompting user input for a "New Date".  

I hope its a little clearer.  Let me know if you need something else.  
(also, the double entry for PIF for 443 days is actually OK...you had mentioned something about that before in the other question).

here is a visual:
excel
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
ASKER CERTIFIED SOLUTION
Gustav Brock

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
pdvsa

ASKER
Thats simply amazing.  Perfect.  

thank you.  :)
Gustav Brock

You are welcome!

/gustav