Re: a dynamic query needing a sum function
- From: OldPro <rrosskopf@xxxxxxxxxxxxx>
- Date: Wed, 29 Aug 2007 14:01:47 -0700
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
.
- Follow-Ups:
- Re: a dynamic query needing a sum function
- From: Philip_collins
- Re: a dynamic query needing a sum function
- 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
- a dynamic query needing a sum function
- Prev by Date: Re: Help!!! Visual Basic goof
- Next by Date: Re: Problem with totals on subforms
- Previous by thread: Re: a dynamic query needing a sum function
- Next by thread: Re: a dynamic query needing a sum function
- Index(es):
Relevant Pages
|
|