Field Update using DSUM: Field joins are not working correctly

ddohnggo

New member
Local time
Today, 06:11
Joined
Aug 29, 2007
Messages
3
I know there are numerous threads regarding dsum() on the forum, but I wasn't able to find the exact answer to my problem.

The root of my problem is that I'm trying to update a field on a table using dsum, which references another query to update the table. Although I have all of the correct keys from the physical table joined to the query in the dsum function, the code/ms access seems to ignore the joins. As a result, all payees are having their "vol" field set instead of a select subset.

Query (GetTxnVolAmtTR"):

SELECT p.payee_id, sum(txn_volume) AS vol, t.market, t.period_id
FROM ft_payees AS p, ft_txn_summary AS t
WHERE p.payee_id=t.payee_id And p.market=t.market
GROUP BY t.payee_id, t.period_id, t.market, p.payee_id;


Update statement (references the query above):

UPDATE tmp_ft_component AS rc
SET rc.volume = Dsum("vol","GetTxnVolAmtTR","GetTxnVolAmtTR.payee_id= " & [rc.payee_id] And "GetTxnVolAmtTR.market= " & [rc.market] And "GetTxnVolAmtTR.period_id= " & [rc.period_id] & "")
WHERE rc.component_name='Total Revenue';

as you can see, I have all of the fields I want joined, but the code seems to ignore this. I've tried looking at this site: http://www.mvps.org/access/general/gen0018.htm , but haven't found my answer. Any help would be much appreciated!
 
The syntax you used for the DSum expression is incorrect. Try the following:

DSum("vol", "GetTxnVolAmtTR", "GetTxnVolAmtTR.payee_ id= " & [rc.payee_id] & " And GetTxnVolAmtTR.market= " & [rc.market] & " And GetTxnVolAmtTR.period_id= " & [rc.period_id] & "")
 
hmmm, now the values are null.

actually, does anyone know if query results can be joined to like views? i.e. Update <table> inner join <query> on .... this may be a better solution for my problem.

i tried it and it didn't work for me, but i may have gotten the syntax incorrect.
 
It may have no effect at all, but I'd be tempted to rewrite these queries without the aliases.
 

Users who are viewing this thread

Back
Top Bottom