473,387 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

A Totals Query That Doesn't Total

I have the following in my code:

strSQL = "SELECT tblTransactions.PshpID, tblTransactions.TransDate, "
_
& " Sum(tblTransactions.DDAmount) AS SumDDAmount FROM tblTransactions
" _
& "INNER JOIN tblMonthly ON tblTransactions.PshpID =
tblMonthly.PshpID " _
& "WHERE tblTransactions.TransDate BETWEEN #12/31/03# AND #05/31/04#
" _
& "GROUP BY tblTransactions.PshpID, tblTransactions.TransDate"

Set rsTrans = dbs.OpenRecordset(strSQL, dbOpenDynaset)

This compiles and runs, but instead of totaling DDAmount on PshpID, it
returns individual records. tblMonthly contains only unique PshpID.

(Must be something really simple, but apparently I'm at the stage
where another set of eyes is needed. Thanks!)

Yisroel
Nov 13 '05 #1
8 1727
If PshpID is unique then you will get a record per record summation.

try

strSQL = "SELECT tblTransactions.TransDate, " _
& " Sum(tblTransactions.DDAmount) AS SumDDAmount " _
& "FROM tblTransactions " _
& "INNER JOIN tblMonthly " _
& "ON tblTransactions.PshpID = tblMonthly.PshpID " _
& "WHERE tblTransactions.TransDate " _
& "BETWEEN #12/31/03# AND #05/31/04# " _
& "GROUP BY tblTransactions.TransDate"
This will give you
The total DDAmount per TransDate where records exist in tblTransactions
with corresponding records in tblMonthly
--
Terry Kreft
MVP Microsoft Access
"Yisroel Markov" <ey*******@iname.com> wrote in message
news:2f**************************@posting.google.c om...
I have the following in my code:

strSQL = "SELECT tblTransactions.PshpID, tblTransactions.TransDate, "
_
& " Sum(tblTransactions.DDAmount) AS SumDDAmount FROM tblTransactions
" _
& "INNER JOIN tblMonthly ON tblTransactions.PshpID =
tblMonthly.PshpID " _
& "WHERE tblTransactions.TransDate BETWEEN #12/31/03# AND #05/31/04#
" _
& "GROUP BY tblTransactions.PshpID, tblTransactions.TransDate"

Set rsTrans = dbs.OpenRecordset(strSQL, dbOpenDynaset)

This compiles and runs, but instead of totaling DDAmount on PshpID, it
returns individual records. tblMonthly contains only unique PshpID.

(Must be something really simple, but apparently I'm at the stage
where another set of eyes is needed. Thanks!)

Yisroel

Nov 13 '05 #2
Your query lotals per each TransDate, which looks as individual
records. Remove TransDate from SELECT. Galina
ey*******@iname.com (Yisroel Markov) wrote in message news:<2f**************************@posting.google. com>...
I have the following in my code:

strSQL = "SELECT tblTransactions.PshpID, tblTransactions.TransDate, "
_
& " Sum(tblTransactions.DDAmount) AS SumDDAmount FROM tblTransactions
" _
& "INNER JOIN tblMonthly ON tblTransactions.PshpID =
tblMonthly.PshpID " _
& "WHERE tblTransactions.TransDate BETWEEN #12/31/03# AND #05/31/04#
" _
& "GROUP BY tblTransactions.PshpID, tblTransactions.TransDate"

Set rsTrans = dbs.OpenRecordset(strSQL, dbOpenDynaset)

This compiles and runs, but instead of totaling DDAmount on PshpID, it
returns individual records. tblMonthly contains only unique PshpID.

(Must be something really simple, but apparently I'm at the stage
where another set of eyes is needed. Thanks!)

Yisroel

Nov 13 '05 #3
"Yisroel Markov" <ey*******@iname.com> wrote in message
news:2f**************************@posting.google.c om...
I have the following in my code:

strSQL = "SELECT tblTransactions.PshpID, tblTransactions.TransDate, "
_
& " Sum(tblTransactions.DDAmount) AS SumDDAmount FROM tblTransactions
" _
& "INNER JOIN tblMonthly ON tblTransactions.PshpID =
tblMonthly.PshpID " _
& "WHERE tblTransactions.TransDate BETWEEN #12/31/03# AND #05/31/04#
" _
& "GROUP BY tblTransactions.PshpID, tblTransactions.TransDate"

Set rsTrans = dbs.OpenRecordset(strSQL, dbOpenDynaset)

This compiles and runs, but instead of totaling DDAmount on PshpID, it
returns individual records. tblMonthly contains only unique PshpID.

(Must be something really simple, but apparently I'm at the stage
where another set of eyes is needed. Thanks!)


Without seeing your table design there's no way to tell what the problem is.
Try printing the sSQL variable to the immediate window and copy to a new
query to test the SQL. Otherwise post your table structure with some sample
data and the output you need.
Nov 13 '05 #4
Galina wrote:
Your query lotals per each TransDate, which looks as
individual records. Remove TransDate from SELECT.


Galina, I can't do that. I need to total on PshpID only, but first the
SQL has to select all transactions whose TransDate falls into this
range. The range is hard-coded right now, but eventually it will need to
use tblMonthly.BegDate and an ending date from an open form. Can I do
that?

Spasibo!

Yisroel

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #5
To follow up and cut to the chase:

Thanks to all who responded. What I'm trying to do is this:

I have a tblMonthly, which has a list of clients. Each has a unique
PshpID and a beginning date (BegDate), which varies from client to
client. I also have a tblTransactions, which contains multiple
transactions for each client for many TransDates, each tagged with
their PshpID.

What I need to do is, for each client, select all transactions between
BegDate and a report date (fed from a user form and the same for all
clients), sum them up and write the sum to tblMonthly in the
corresponding client's record. This is proving unduly difficult (well,
I am a self-taught amateur at this). It seems impossible to select
such transactions (with variable beginning date) and sum them up in a
single SQL statement - there are problems using GROUP BY on TransDate
(which I don't want to do - I need to sum by PshpID - but SQL demands
it). I wrote a query to do that, first with hard-coded dates, and then
created another SQL-based recordset to sum up the amounts, thus
avoiding the problem with grouping on TransDate. That worked until I
replaced the ending date (5/31/04 in the example earlier in the
thread) with a reference to a textbox control on the user form - the
code saw it (I checked via a temporary string variable), but
OpenRecordset method responded with "Too few parameters. Expected 1."
So I created another table to hold the selected data, and will need to
sum it with another SQL-based recordset, and then write it to
tblMonthly... isn't there a more elegant way of doing this?

And is there a good book on Access VBA which goes a bit beyond the
basics, and has a good error reference?

ey*******@iname.com (Yisroel Markov) wrote in message news:<2f**************************@posting.google. com>...
I have the following in my code:

strSQL = "SELECT tblTransactions.PshpID, tblTransactions.TransDate, "
_
& " Sum(tblTransactions.DDAmount) AS SumDDAmount FROM tblTransactions
" _
& "INNER JOIN tblMonthly ON tblTransactions.PshpID =
tblMonthly.PshpID " _
& "WHERE tblTransactions.TransDate BETWEEN #12/31/03# AND #05/31/04#
" _
& "GROUP BY tblTransactions.PshpID, tblTransactions.TransDate"

Set rsTrans = dbs.OpenRecordset(strSQL, dbOpenDynaset)

This compiles and runs, but instead of totaling DDAmount on PshpID, it
returns individual records. tblMonthly contains only unique PshpID.

(Must be something really simple, but apparently I'm at the stage
where another set of eyes is needed. Thanks!)

Yisroel

Nov 13 '05 #6
don't include 'transDate' in the SELECT string, ie.
strSQL = "SELECT tblTransactions.PshpID, " _
& " Sum(tblTransactions.DDAmount) AS SumDDAmount FROM tblTransactions" _
& "INNER JOIN tblMonthly ON tblTransactions.PshpID = tblMonthly.PshpID " _
& "WHERE tblTransactions.TransDate BETWEEN #12/31/03# AND #05/31/04# " _
& "GROUP BY tblTransactions.PshpID"

Set rsTrans = dbs.OpenRecordset(strSQL, dbOpenDynaset)

ey*******@iname.com (Yisroel Markov) wrote in message news:<2f**************************@posting.google. com>...
I have the following in my code:

strSQL = "SELECT tblTransactions.PshpID, tblTransactions.TransDate, "
_
& " Sum(tblTransactions.DDAmount) AS SumDDAmount FROM tblTransactions
" _
& "INNER JOIN tblMonthly ON tblTransactions.PshpID =
tblMonthly.PshpID " _
& "WHERE tblTransactions.TransDate BETWEEN #12/31/03# AND #05/31/04#
" _
& "GROUP BY tblTransactions.PshpID, tblTransactions.TransDate"

Set rsTrans = dbs.OpenRecordset(strSQL, dbOpenDynaset)

This compiles and runs, but instead of totaling DDAmount on PshpID, it
returns individual records. tblMonthly contains only unique PshpID.

(Must be something really simple, but apparently I'm at the stage
where another set of eyes is needed. Thanks!)

Yisroel

Nov 13 '05 #7
Yisroel
Pozhaluysta.
Of course you can do it! Make criteria in your query between dates,
however you want it, but uncheck (remove tick) in the Show: line and
select Where in the Total: line of query design. And your query will
select between dates and sum PshpID only. You don't need any code for
it.
Galina
Yisroel Markov <ey*******@iname.com> wrote in message news:<40**********************@news.newsgroups.ws> ...
Galina wrote:
Your query lotals per each TransDate, which looks as
individual records. Remove TransDate from SELECT.


Galina, I can't do that. I need to total on PshpID only, but first the
SQL has to select all transactions whose TransDate falls into this
range. The range is hard-coded right now, but eventually it will need to
use tblMonthly.BegDate and an ending date from an open form. Can I do
that?

Spasibo!

Yisroel

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 13 '05 #8
Hi
What do you need to write your sums into a table for? Anything, what
can be calculated, should not be kept in tables as a general
principle. You only make your life more difficult.
I don't think that you need any coding here. If we leave aside writing
sums into a table, which is not needed, what the query should provide
results for? A Form? a report?
If you have an error message "Too few parameters. Expected 1." it
means that you need to design a parameter query and code it's excution
correctly. If you still think you need it, search this group with key
words "parameter query". Sometime ago we discuss the topic quite a
lot.
I am tempted to suggest you to e-mail your database. It seems simpler
to make this query for you rather then to write long explanations.
Galina

ey*******@iname.com (Yisroel Markov) wrote in message news:<2f**************************@posting.google. com>...
To follow up and cut to the chase:

Thanks to all who responded. What I'm trying to do is this:

I have a tblMonthly, which has a list of clients. Each has a unique
PshpID and a beginning date (BegDate), which varies from client to
client. I also have a tblTransactions, which contains multiple
transactions for each client for many TransDates, each tagged with
their PshpID.

What I need to do is, for each client, select all transactions between
BegDate and a report date (fed from a user form and the same for all
clients), sum them up and write the sum to tblMonthly in the
corresponding client's record. This is proving unduly difficult (well,
I am a self-taught amateur at this). It seems impossible to select
such transactions (with variable beginning date) and sum them up in a
single SQL statement - there are problems using GROUP BY on TransDate
(which I don't want to do - I need to sum by PshpID - but SQL demands
it). I wrote a query to do that, first with hard-coded dates, and then
created another SQL-based recordset to sum up the amounts, thus
avoiding the problem with grouping on TransDate. That worked until I
replaced the ending date (5/31/04 in the example earlier in the
thread) with a reference to a textbox control on the user form - the
code saw it (I checked via a temporary string variable), but
OpenRecordset method responded with "Too few parameters. Expected 1."
So I created another table to hold the selected data, and will need to
sum it with another SQL-based recordset, and then write it to
tblMonthly... isn't there a more elegant way of doing this?

And is there a good book on Access VBA which goes a bit beyond the
basics, and has a good error reference?

ey*******@iname.com (Yisroel Markov) wrote in message news:<2f**************************@posting.google. com>...
I have the following in my code:

strSQL = "SELECT tblTransactions.PshpID, tblTransactions.TransDate, "
_
& " Sum(tblTransactions.DDAmount) AS SumDDAmount FROM tblTransactions
" _
& "INNER JOIN tblMonthly ON tblTransactions.PshpID =
tblMonthly.PshpID " _
& "WHERE tblTransactions.TransDate BETWEEN #12/31/03# AND #05/31/04#
" _
& "GROUP BY tblTransactions.PshpID, tblTransactions.TransDate"

Set rsTrans = dbs.OpenRecordset(strSQL, dbOpenDynaset)

This compiles and runs, but instead of totaling DDAmount on PshpID, it
returns individual records. tblMonthly contains only unique PshpID.

(Must be something really simple, but apparently I'm at the stage
where another set of eyes is needed. Thanks!)

Yisroel

Nov 13 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Deano | last post by:
OK, I'm working on a solution to the following problem but there are other ways to skin a cat as they say... Here's the table (simplified); ID EmployeeName SalaryAcc 1 Brown ...
8
by: Tony Williams | last post by:
I have a database that hold s figures for each quarter. I want to create a query whereby the user can ask for the running total of the data upto the quarter they enter into a prompt. The database...
2
by: deko | last post by:
I have a number of queries that pull totals from different tables. How do I sum the different total values from each query to get a grand total? I tried using a Union query like this: SELECT...
4
by: New Guy | last post by:
I'm trying to work with a system that somebody else built and I am confounded by the following problem: There is a table of payments and a table of charges. Each client has charges and payments...
2
by: BerkshireGuy | last post by:
I have the following code: Dim strSQL As String Dim DB As DAO.Database Dim RS As DAO.Recordset Dim intNumOfPaid, intNumOfHypoed, intNumOfNotTaken, intNumOfDeclined, intNumOfWasted,...
9
by: JJM0926 | last post by:
I'm trying to create a running totals query in access 97. I have followed the directions on how to do it from Microsofts website article id 138911. I took their code they had and replaced it with...
4
by: Micheal | last post by:
Greetings Access Group, Being relatively new to Access, I try to work through problems on my own and have been very successful, although I have a conundrum that I have been working on for two days...
2
by: Ron | last post by:
Hi All, I've got a main form (frmMain) with 5 subforms on it. All subforms are linked to different hidden controls on frmMain. The purpose of this form is to record payments by 'source'...
2
by: plaguna | last post by:
I’m trying to get some calculations in a Query. Four fields are from a table x, and base on those fields I need to get some combination of Totals. This is the scenario. Total A : + from table x...
2
by: Bytesmiths | last post by:
I'm using GROUP BY to come up with totals for some items, but would like to either have a grand total at the bottom, or a running total field. I tried to use a variable as I found in several...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.