> Unfortunatelly I need the recordset which is quite complicated. Then I need
> to make a sum of several fields and also with several different conditions.
> Would be nice to have some Sum function but if it does not exist then I must
> write the code.
> Thanks
> Ari
I don't believe it's possible to use DSum to calculate the sum of the
records in an open recordset, or do you have something different in mind?

Signature
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)
> If you are wanting to do it outside SQL and in VBA, then look in VBA Help for
> the DSum function.
[quoted text clipped - 5 lines]
> > Thanks
> > Ari
http://www.accessmonster.com/Uwe/Forums.aspx/access-gettingstarted/200607/1
Klatuu - 06 Jul 2006 20:18 GMT
Actually, it is. I tested it both on a recordset based on a query and on a
recordset based on a table. The query included two tables. Here is what I
did in the immediate window for the query version:
set rst = currentdb.OpenRecordset("zztest")
?dsum("[mar]",rst.Name)
4272692.156882
> I don't believe it's possible to use DSum to calculate the sum of the
> records in an open recordset, or do you have something different in mind?
[quoted text clipped - 14 lines]
> > >
> http://www.accessmonster.com/Uwe/Forums.aspx/access-gettingstarted/200607/1
Douglas J Steele - 06 Jul 2006 21:05 GMT
Really! I did not know that.

Signature
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)
> Actually, it is. I tested it both on a recordset based on a query and on a
> recordset based on a table. The query included two tables. Here is what I
[quoted text clipped - 19 lines]
> > > > Thanks
> > > > Ari
http://www.accessmonster.com/Uwe/Forums.aspx/access-gettingstarted/200607/1
Klatuu - 06 Jul 2006 21:13 GMT
I did not test it in a running VBA procedure, only the immediate window. I
don't know that there should be a difference.
> Really! I did not know that.
>
[quoted text clipped - 29 lines]
> > >
> http://www.accessmonster.com/Uwe/Forums.aspx/access-gettingstarted/200607/1
arista - 07 Jul 2006 11:16 GMT
So I was trying it with no success. Is it really possible in VBA ?
Or perhaps is there any option how to use the already defined string strSQL,
which contains "a good query", to open a query in VBA e.g. qryA and then use
DSum as DSum("[field]", qryA, nejake podminky) ?
I do not want to make a stiff query in Access because there are already
plenty of them in my application.
Thanks
Klatuu - 07 Jul 2006 14:14 GMT
Yes, if you view my previous post, you will see the answer.
You just use the DSum on the domain whether it is an existing query or a
table. You cannot use an SQL string. It doesn't matter whether you have the
recordset open or not.
As to using SQL instead of stored queries. Stored queries execute faster
than an SQL string because they are already optimized and compiled. Using
SQL directly is best used when you have varying parameters and it is easier
to build an SQL string.
> So I was trying it with no success. Is it really possible in VBA ?
> Or perhaps is there any option how to use the already defined string strSQL,
[quoted text clipped - 3 lines]
> plenty of them in my application.
> Thanks
arista - 07 Jul 2006 15:22 GMT
I have object myData which contains the SQL and I can access to its fields as
myData!fieldname
from your example I do not see where is the defined string and also do not
understand what is rst.name
rgs
Klatuu - 07 Jul 2006 15:46 GMT
Here we open the recordset. zztest is a stored query:
set rst = currentdb.OpenRecordset("zztest")
Here we are doing a DSum on a field named mar in the Recordset. The second
argument of the DSum function is the Domain Name. It expects the name of a
Domain as a string. In this case, the Domain is the open Recordset. We can
pass the name as a string using the Name property of the recordset.
?dsum("[mar]",rst.Name)
If you can post the code where you are opening your recordset, I will have a
look and perhaps offer a suggestion.
> I have object myData which contains the SQL and I can access to its fields as
> myData!fieldname
> from your example I do not see where is the defined string and also do not
> understand what is rst.name
> rgs