A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Help with running balance



 
 
Thread Tools Display Modes
  #11  
Old January 5th, 2009, 12:12 AM posted to microsoft.public.access.queries
Johnny[_5_]
external usenet poster
 
Posts: 50
Default Help with running balance

It worked Bob thanks very much

Johnny
  #12  
Old January 5th, 2009, 09:52 PM posted to microsoft.public.access.queries
Johnny[_5_]
external usenet poster
 
Posts: 50
Default Help with running balance

Hi Ken,

Once more I request your help!
I used the sugestion you gave me and with Bob Barrows help I could
make it work!
That way, the query returns the Balance of all transactions in
Transactions table. What I need is that the query return all all
transactions in Transactions table for a specific person (ClientID).

Could the following be a solution??
SELECT TransDate, TransValue, ClientID,
DSum("TransValue", "Transactions",
"TransDate = #" & Format(T1.TransDate, "yyyy-mm-dd") &
"# And (TransactionID = " & T1.TransactionID &
" Or TransDate #" & Format(T1.TransDate, "yyyy-mm-dd") & "#)
And T1.ClientID = [Forms]![MyForm]![MyControl]")
AS Balance
FROM Transactions AS T1
ORDER BY TransDate DESC , TransactionID DESC;

[Forms]![MyForm]![MyControl] is a combo box returning a number!

Thanks once more for the suport
Johnny


  #13  
Old January 6th, 2009, 12:35 PM posted to microsoft.public.access.queries
John Spencer (MVP)
external usenet poster
 
Posts: 217
Default Help with running balance

SELECT TransDate, TransValue, ClientID,
DSum("TransValue", "Transactions",
"TransDate = #" & Format(T1.TransDate, "yyyy-mm-dd") &
"# And (TransactionID = " & T1.TransactionID &
" Or TransDate #" & Format(T1.TransDate, "yyyy-mm-dd") & "#)
And ClientID =" & T1.ClientID)
AS Balance
FROM Transactions AS T1
ORDER BY TransDate DESC , TransactionID DESC;

If you are trying to get all this for one specific client, you might change
the query to

SELECT TransDate, TransValue, ClientID,
DSum("TransValue", "Transactions",
"TransDate = #" & Format(T1.TransDate, "yyyy-mm-dd") &
"# And (TransactionID = " & T1.TransactionID &
" Or TransDate #" & Format(T1.TransDate, "yyyy-mm-dd") & "#)
And ClientID =" & T1.ClientID) AS Balance
FROM Transactions AS T1
WHERE T1.ClientID = [Forms]![MyForm]![MyControl]
ORDER BY TransDate DESC , TransactionID DESC;

Hopefully all the needed parentheses are in the correct place.

Alternative would be to use a subquery to get the Balance
SELECT TransDate, TransValue, ClientID
, (SELECT SUM(TransValue) FROM Transactions as T
WHERE T.ClientID = T1.ClientID
AND (T.TransDate = T1.TransDate
AND T.TransactionID=T1.TransactionID
Or T.TransDate T1.TransDate) As Balance
FROM Transactions AS T1
WHERE T1.ClientID = [Forms]![MyForm]![MyControl]
ORDER BY TransDate DESC , TransactionID DESC;



John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County

Johnny wrote:
Hi Ken,

Once more I request your help!
I used the sugestion you gave me and with Bob Barrows help I could
make it work!
That way, the query returns the Balance of all transactions in
Transactions table. What I need is that the query return all all
transactions in Transactions table for a specific person (ClientID).

Could the following be a solution??
SELECT TransDate, TransValue, ClientID,
DSum("TransValue", "Transactions",
"TransDate = #" & Format(T1.TransDate, "yyyy-mm-dd") &
"# And (TransactionID = " & T1.TransactionID &
" Or TransDate #" & Format(T1.TransDate, "yyyy-mm-dd") & "#)
And T1.ClientID = [Forms]![MyForm]![MyControl]")
AS Balance
FROM Transactions AS T1
ORDER BY TransDate DESC , TransactionID DESC;

[Forms]![MyForm]![MyControl] is a combo box returning a number!

Thanks once more for the suport
Johnny


  #14  
Old January 6th, 2009, 06:46 PM posted to microsoft.public.access.queries
Johnny[_5_]
external usenet poster
 
Posts: 50
Default Help with running balance

Hi John,

I used what you sugested:

SELECT TransDate, TransValue, ClientID,
DSum("TransValue", "Transactions",
"TransDate = #" & Format(T1.TransDate, "yyyy-mm-dd") &
"# And (TransactionID = " & T1.TransactionID &
" Or TransDate #" & Format(T1.TransDate, "yyyy-mm-dd") & "#)
And ClientID =" & T1.ClientID) AS Balance
FROM Transactions AS T1
WHERE T1.ClientID = [Forms]![MyForm]![MyControl]
ORDER BY TransDate DESC , TransactionID DESC;

and it worked like a charm!
Thank you very much for your suport
Johnny
  #15  
Old October 6th, 2009, 07:11 AM posted to microsoft.public.access.queries
Michael Strite
external usenet poster
 
Posts: 3
Default Additional question on top of this one.

This thread has been very helpful to me. However, I have a slightly different need. Instead of feeding the specific ClientID from a separate form, I just need the query to have the running balance by date but tracked per each ClientID. Is there some small modification to this that would make that work?

For example

Date ClientID Transvalue Balance
01/01/09 client1 23 23
01/02/09 client2 12 12
01/06/09 client1 05 28
01/06/09 client3 09 09
01/08/09 client3 14 23
01/20/09 client1 04 32




Johnny wrote:

Help with running balance
10-Jan-09

Hi John,

I used what you sugested:

SELECT TransDate, TransValue, ClientID,
DSum("TransValue", "Transactions",
"TransDate = #" & Format(T1.TransDate, "yyyy-mm-dd") &
"# And (TransactionID = " & T1.TransactionID &
" Or TransDate #" & Format(T1.TransDate, "yyyy-mm-dd") & "#)
And ClientID =" & T1.ClientID) AS Balance
FROM Transactions AS T1
WHERE T1.ClientID = [Forms]![MyForm]![MyControl]
ORDER BY TransDate DESC , TransactionID DESC;

and it worked like a charm!
Thank you very much for your suport
Johnny

EggHeadCafe - Software Developer Portal of Choice
Speed Up Sql Server Data Inserts With SqlBulkCopy
http://www.eggheadcafe.com/tutorials...rver-data.aspx
  #16  
Old October 6th, 2009, 07:12 AM posted to microsoft.public.access.queries
Michael Strite
external usenet poster
 
Posts: 3
Default Additional question on top of this one.

This thread has been very helpful to me. However, I have a slightly different need. Instead of feeding the specific ClientID from a separate form, I just need the query to have the running balance by date but tracked per each ClientID. Is there some small modification to this that would make that work?

For example

Date ClientID Transvalue Balance
01/01/09 client1 23 23
01/02/09 client2 12 12
01/06/09 client1 05 28
01/06/09 client3 09 09
01/08/09 client3 14 23
01/20/09 client1 04 32




Johnny wrote:

Help with running balance
10-Jan-09

Hi John,

I used what you sugested:

SELECT TransDate, TransValue, ClientID,
DSum("TransValue", "Transactions",
"TransDate = #" & Format(T1.TransDate, "yyyy-mm-dd") &
"# And (TransactionID = " & T1.TransactionID &
" Or TransDate #" & Format(T1.TransDate, "yyyy-mm-dd") & "#)
And ClientID =" & T1.ClientID) AS Balance
FROM Transactions AS T1
WHERE T1.ClientID = [Forms]![MyForm]![MyControl]
ORDER BY TransDate DESC , TransactionID DESC;

and it worked like a charm!
Thank you very much for your suport
Johnny

EggHeadCafe - Software Developer Portal of Choice
ASP.NET: Hamburger, Yes! AJAX, "NOT!", Redux!
http://www.eggheadcafe.com/tutorials...urger-yes.aspx
  #17  
Old October 6th, 2009, 07:13 AM posted to microsoft.public.access.queries
Michael Strite
external usenet poster
 
Posts: 3
Default One small change

This thread has been very helpful to me. However, I have a slightly different need. Instead of feeding the specific ClientID from a separate form, I just need the query to have the running balance by date but tracked per each ClientID. Is there some small modification to this that would make that work?

For example

Date ClientID Transvalue Balance
01/01/09 client1 23 23
01/02/09 client2 12 12
01/06/09 client1 05 28
01/06/09 client3 09 09
01/08/09 client3 14 23
01/20/09 client1 04 32



Johnny wrote:

Help with running balance
10-Jan-09

Hi John,

I used what you sugested:

SELECT TransDate, TransValue, ClientID,
DSum("TransValue", "Transactions",
"TransDate = #" & Format(T1.TransDate, "yyyy-mm-dd") &
"# And (TransactionID = " & T1.TransactionID &
" Or TransDate #" & Format(T1.TransDate, "yyyy-mm-dd") & "#)
And ClientID =" & T1.ClientID) AS Balance
FROM Transactions AS T1
WHERE T1.ClientID = [Forms]![MyForm]![MyControl]
ORDER BY TransDate DESC , TransactionID DESC;

and it worked like a charm!
Thank you very much for your suport
Johnny

EggHeadCafe - Software Developer Portal of Choice
Moving to VB.NET - Appelman [aPress]
http://www.eggheadcafe.com/tutorials...t--appelm.aspx
  #18  
Old October 6th, 2009, 01:47 PM posted to microsoft.public.access.queries
vanderghast
external usenet poster
 
Posts: 593
Default Additional question on top of this one.

Using joins:


SELECT a.date, a.clientID, LAST(a.transvalue), SUM(b.transvalue)
FROM tableName As a INNER JOIN tableName AS b
ON a.clientID=b.clientID AND a.date= b.date
GROUP BY a.date, a.clientID

ORDER BY a.clientID, a.date


The Order by clause is optional, and can be used to help to validate the
result.


Vanderghast, Access MVP



"Michael Strite" wrote in message ...
This thread has been very helpful to me. However, I have a slightly
different need. Instead of feeding the specific ClientID from a separate
form, I just need the query to have the running balance by date but
tracked per each ClientID. Is there some small modification to this that
would make that work?

For example

Date ClientID Transvalue Balance
01/01/09 client1 23 23
01/02/09 client2 12 12
01/06/09 client1 05 28
01/06/09 client3 09 09
01/08/09 client3 14 23
01/20/09 client1 04 32




Johnny wrote:

Help with running balance
10-Jan-09

Hi John,

I used what you sugested:

SELECT TransDate, TransValue, ClientID,
DSum("TransValue", "Transactions",
"TransDate = #" & Format(T1.TransDate, "yyyy-mm-dd") &
"# And (TransactionID = " & T1.TransactionID &
" Or TransDate #" & Format(T1.TransDate, "yyyy-mm-dd") & "#)
And ClientID =" & T1.ClientID) AS Balance
FROM Transactions AS T1
WHERE T1.ClientID = [Forms]![MyForm]![MyControl]
ORDER BY TransDate DESC , TransactionID DESC;

and it worked like a charm!
Thank you very much for your suport
Johnny

EggHeadCafe - Software Developer Portal of Choice
ASP.NET: Hamburger, Yes! AJAX, "NOT!", Redux!
http://www.eggheadcafe.com/tutorials...urger-yes.aspx


  #19  
Old October 6th, 2009, 06:19 PM posted to microsoft.public.access.queries
Marshall Barton
external usenet poster
 
Posts: 5,361
Default One small change

Try removing the query's WHERE clause.
--
Marsh
MVP [MS Access]


Michael Strite wrote:
This thread has been very helpful to me. However, I have a slightly different need. Instead of feeding the specific ClientID from a separate form, I just need the query to have the running balance by date but tracked per each ClientID. Is there some small modification to this that would make that work?

For example

Date ClientID Transvalue Balance
01/01/09 client1 23 23
01/02/09 client2 12 12
01/06/09 client1 05 28
01/06/09 client3 09 09
01/08/09 client3 14 23
01/20/09 client1 04 32



Johnny wrote:

Help with running balance
10-Jan-09

Hi John,

I used what you sugested:

SELECT TransDate, TransValue, ClientID,
DSum("TransValue", "Transactions",
"TransDate = #" & Format(T1.TransDate, "yyyy-mm-dd") &
"# And (TransactionID = " & T1.TransactionID &
" Or TransDate #" & Format(T1.TransDate, "yyyy-mm-dd") & "#)
And ClientID =" & T1.ClientID) AS Balance
FROM Transactions AS T1
WHERE T1.ClientID = [Forms]![MyForm]![MyControl]
ORDER BY TransDate DESC , TransactionID DESC;

and it worked like a charm!
Thank you very much for your suport
Johnny

EggHeadCafe - Software Developer Portal of Choice
Moving to VB.NET - Appelman [aPress]
http://www.eggheadcafe.com/tutorials...t--appelm.aspx


  #20  
Old October 7th, 2009, 03:28 AM posted to microsoft.public.access.queries
inept_webmaster
external usenet poster
 
Posts: 4
Default One small change

Many thanks Marshall & vanderghast for your attempts to help a
newbie... I hesitate to bother you but I seem to be stuck again.
When I run my query with the following query field included, it gives
me a syntax error. I am sure that I am missing some critical
paretheses but for the life of me I cannot seem to figure out where to
put them. I am still trying to figure out the logic behind these SQL
queries... Forgive my ignorance but can you tell me what I need to
change with the following statement.


Balance: SELECT a.TransDate, a.CustID, LAST(a.ChargeAmount), SUM
(b.ChargeAmount)
FROM Accounts As a INNER JOIN Accounts AS b
ON a.CustID=b.CustID AND a.TransDate= b.TransDate
GROUP BY a.TransDate, a.CustID
ORDER BY a.CustID, a.TransDate
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 05:23 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.