Re: a dynamic query needing a sum function
- From: Philip_collins@xxxxxxxxxxx
- Date: Thu, 30 Aug 2007 02:18:07 -0700
On 29 Aug, 22:01, OldPro <rrossk...@xxxxxxxxxxxxx> wrote:
On Aug 29, 3:13 pm, Philip_coll...@xxxxxxxxxxx wrote:
On 29 Aug, 19:35, OldPro <rrossk...@xxxxxxxxxxxxx> wrote:
On Aug 29, 1:11 pm, Philip_coll...@xxxxxxxxxxx wrote:
First of all, it is bad form to use Date or Time as a field name,
variable name or control name, as these are common functions and
keywords.
Second, DSUM( ) will give you a total based on a SQL query.
Third, SQL can return records or record totals, not both mixed. That
being said, it is possible to have an aggregate sum, where only the
last record would show the total. This is also problematic as Access
doesn't guarantee that any particular record will be the last one.
This will give you a one record total:
strsql = "SELECT SUM([NetKG]) AS NetKG_Total FROM tblVanDetails WHERE
[RegistrationNo] = '" & zz & "'"- Hide quoted text -
- Show quoted text -
Thanks for the response. how do I place that sql within the above code
to get the form to see the total? I'm quite happy to change the field
names!
regards
Phil- Hide quoted text -
- Show quoted text -
It depends on when you want the total to show. If you want it to show
after zz is updated, then put the code in that controls' afterupdate
event. You will want the total control to be a label.
You can use either...
lblTotal.Caption=DSUM("NetKG","tblVanDetails", "[RegistrationNo] = "
& zz )
or ...
Dim cTotal as currency
Dim db as dao.database
Dim rs as dao.recordset
set db=currentdb()
strsql = "SELECT SUM([NetKG]) AS NetKG_Total FROM tblVanDetails
WHERE
[RegistrationNo] = " & zz
set rs=db.openrecordset(strsql,dbopensnapshot)
if rs.eof then
lblTotal.Caption=""
else
lblTotal.Caption=rs!NetKG_Total
endif
rs.close
set rs=nothing
db.close
set db=nothing- Hide quoted text -
- Show quoted text -
Thanks for the help! I dont seem to be able to get my head round it!
so a little more info might help. I build the query to show the how
many times the vehicle comes onto the site and how much refuse it has
left, I then open another form frmWeightsTotals using the qry as the
record source. What I want to do is put a control on the forms footer
showing the number of visits and the total weight. it's probably me,
but I tried both your solutions thinking that i might refer to the
first form, but i kept getting syntax errors
Thanks again for the help.
regards
Phil
.
- References:
- a dynamic query needing a sum function
- From: Philip_collins
- Re: a dynamic query needing a sum function
- From: OldPro
- Re: a dynamic query needing a sum function
- From: Philip_collins
- Re: a dynamic query needing a sum function
- From: OldPro
- a dynamic query needing a sum function
- Prev by Date: Re: MSLDBUSR.DLL
- Next by Date: Re: MSLDBUSR.DLL
- Previous by thread: Re: a dynamic query needing a sum function
- Next by thread: Problem with totals on subforms
- Index(es):
Relevant Pages
|