SQL Query - DSum - Recordset - VBA

G

Guest

Hello,

Working on a table counting about 12'000 rows, I have the following issue :
I use a DSum function inside a Make table query adding a column containing a
total based on specific criteria to each of these rows. The thing is that the
query takes a huge amount of time to complete its task and create the new
table. In the past, I transposed the DSum function & result in SQL. But in
this case, I need two identical tables to perform this operation. This
solution can't be used anymore due to size issues.

Then, I am wondering if it would be more "efficient" to work through VBA &
Recordsets. More precisely, would it be possible (and faster) to take the
content of the original table and store it in a recordset, perform the DSum
function and save the result in a new table ?! If expecting a significant
speed difference in the data treatment... how could I do it ? Any suggestions
or related web page would be great. TIA for your cooperation.

Acheron
 
D

Duane Hookom

You might get better performance using either a subquery or a custom
function to replace the DSum(). Without a clue as to your DSum(), it's hard
to give a definitive answer.
 
G

Guest

Ok. Here we go :

After applying several filters on my records (the first table counts about 1
mio rows) based on several criteria, I make a new table. On this one, I need
to get running totals (and save the result in a new table). The DSum function
I use goes like this :

DSum("[AmountToSum]";"MyTable";"[Year] = " & [Year] & " And CLng([Date]) <="
& CLng([Date]) & " And [MyGroup1] Like " & Chr(34) & [MyGroup1] & Chr(34) & "
And [MyGroup2] Like " & Chr(34) & [MyGroup2] & Chr(34))

That's it !

Hope this will help. TIA

Acheron
 
D

Duane Hookom

Do the MyGroup1 and MyGroup2 values contain wildcards or are they just the
text?
The subquery would be like:
(SELECT Sum([AmountToSum]) FROM MyTable z WHERE z.[Year] = [Year] And
CLng(z.[Date]) <= CLng([Date]) And z.[MyGroup1] Like [MyGroup1] And
z.[MyGroup2] Like [MyGroup2] )

If the group expressions don't contain wildcards, then replace the " Like "
with " = ".


--
Duane Hookom
MS Access MVP


Acheron said:
Ok. Here we go :

After applying several filters on my records (the first table counts about
1
mio rows) based on several criteria, I make a new table. On this one, I
need
to get running totals (and save the result in a new table). The DSum
function
I use goes like this :

DSum("[AmountToSum]";"MyTable";"[Year] = " & [Year] & " And CLng([Date])
<="
& CLng([Date]) & " And [MyGroup1] Like " & Chr(34) & [MyGroup1] & Chr(34)
& "
And [MyGroup2] Like " & Chr(34) & [MyGroup2] & Chr(34))

That's it !

Hope this will help. TIA

Acheron
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

DSum Function 3
dsum sytax error 5
DCount & DSum 8
DSum 1
dsum 1
DSum 4
Using DSUM to get running total on a filtered form 0
Parameter Query with DSum 1

Top