?
Solved

Day Count - User Input

Posted on 2016-09-24
6
Medium Priority
?
47 Views
Last Modified: 2016-09-25
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
0
Comment
Question by:pdvsa
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 21
ID: 41814059
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
0
 
LVL 51

Expert Comment

by:Gustav Brock
ID: 41814094
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
0
 

Author Comment

by:pdvsa
ID: 41814364
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
0
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
LVL 51

Accepted Solution

by:
Gustav Brock earned 2000 total points
ID: 41814454
Oh, it starts to get dirty, but this query seems to do:
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] And 
                (Select Count(*) From Q_Disbursement As Q 
                Where Q.FacilityType = Q_Disbursement.FacilityType 
                    And Q.ValueDate > Q_Disbursement.ValueDate) = 1,[Enter Last Date:],Q.[ValueDate])) 
            From Q_Disbursement As Q 
            Where Q.FacilityType = Q_Disbursement.FacilityType 
                And Q.ValueDate > Q_Disbursement.ValueDate)) AS 
    DayCount
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

Output:

Demo
/gustav
0
 

Author Closing Comment

by:pdvsa
ID: 41814623
Thats simply amazing.  Perfect.  

thank you.  :)
0
 
LVL 51

Expert Comment

by:Gustav Brock
ID: 41814643
You are welcome!

/gustav
0

Featured Post

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Suggested Courses

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question