473,383 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

update problem

Hi,

I'm trying to update a row in a table. The value in this record must
be set to the sum of a column from another table. I can't seem to figure
this out, i keeps saying my query is not updateable. Any sugguestions.
Thanks in advance.

TIA
Nov 13 '05 #1
6 1851
Before you do this, could there be valid situations where the stored total
should be different from the sum in the other table? If not, don't take on
the responsibility to keep this total always right, regardless of how
records are added/edited/deleted in the other table. Not worth it.

If you want to do it anyway, you should be able to use a DSum() or a
subquery into the UPDATE clause of the action query, e.g.:
UPDATE tblOrder SET MyTotal =
(SELECT SUM(Amount) FROM tblOrderDetail
WHERE tblOrderDetail.OrderID = tblOrder.OrderID);

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"someguy" <in*********@yahoo.com> wrote in message
news:Xn*********************************@216.196.9 7.142...

I'm trying to update a row in a table. The value in this record must
be set to the sum of a column from another table. I can't seem to figure
this out, i keeps saying my query is not updateable. Any sugguestions.
Thanks in advance.

TIA

Nov 13 '05 #2
Hi Allen,
Thanks for replaying. The problem i have is that the tables are not
related, there is no common field and therefore there is no join option.
Sorry if this sounds like a trivial question but i'm not too familiar
with Access.

Thanks,

Inderjit
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #3
So how do you know which records to total?

If you just want the total of all records, it's exactly the same, without
the WHERE clause in the subquery. If there is some criteria you can specify,
use that as the WHERE clause in the subquery.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Inderjit Rai" <in*********@rogers.com> wrote in message
news:41**********@127.0.0.1...

Thanks for replaying. The problem i have is that the tables are not
related, there is no common field and therefore there is no join option.
Sorry if this sounds like a trivial question but i'm not too familiar
with Access.

Nov 13 '05 #4
Hi Allen,

Yes I am trying to get the total for the whole column in the other
table. I tried it without the where clause and it stills says 'must be
an updateable query'. Here's my code;

Update Table1
Set Table1.num1 = (Select Sum(Table2.num2) from Table2)

Thanks again

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #5
Then just try a DSum():

strSQL = "UPDATE Table1 SET Table1.Num1 = " & Nz(DSum("Num2", "Table2"),0) &
";"
dbEngine(0)(0).Execute strSQL, dbFailOnError

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Inderjit Rai" <in*********@rogers.com> wrote in message
news:41**********@127.0.0.1...
Hi Allen,

Yes I am trying to get the total for the whole column in the other
table. I tried it without the where clause and it stills says 'must be
an updateable query'. Here's my code;

Update Table1
Set Table1.num1 = (Select Sum(Table2.num2) from Table2)

Thanks again

Nov 13 '05 #6
Hey Allen,

Dsum works. Thanks for all your help! Let me if you ever need help
with DB2 or Cystal Reports.

Inderjit

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: al | last post by:
Greetings, In the customers table in Northwind db, one can update PK (customerid) and all other fields in the same table. My question is how can you do this in the udpate stat. That is, if one...
1
by: Gent | last post by:
am using FOR UPDATE triggers to audit a table that has 67 fields. My problem is that this slows down the system significantly. I have narrowed down the problem to the size (Lines of code) that need...
2
by: serge | last post by:
/* This is a long post. You can paste the whole message in the SQL Query Analyzer. I have a scenario where there are records with values pointing to wrong records and I need to fix them using an...
2
by: Niyazi | last post by:
Hi, I have not understand the problem. Before all the coding with few application everything worked perfectly. Now I am developing Cheque Writing application and when the cheque is clear the...
8
by: Maxi | last post by:
There is a lotto system which picks 21 numbers every day out of 80 numbers. I have a table (name:Lotto) with 22 fields (name:Date,P1,P2....P21) Here is the structure and sample data: ...
13
by: abdoly | last post by:
i wrote a code to update datagrid with the datagrid updatecommand but i cant get the updated values after being update that is the code private void DataGrid1_UpdateCommand(object source,...
8
by: Zorpiedoman | last post by:
I keep getting a concurrency exception the second time I make a change and attempt to update a dataadapter. It appears this is by design, so there must be something I can do to avoid it. ...
1
by: cindy | last post by:
this is the call private void Page_Load(object sender, System.EventArgs e) { OdbcConnection connection = new OdbcConnection ("DSN=PFW52"); CreateDataAdapter(connection); } this is the code,...
5
by: =?Utf-8?B?UlBhcmtlcg==?= | last post by:
I used the wizard to generate a typed dataset for my table and let it create my SPROCs. It created everything, and the GetData() method and the custom GetByUserName query works great, but when I...
11
by: SAL | last post by:
Hello, I have a Gridview control (.net 2.0) that I'm having trouble getting the Update button to fire any kind of event or preforming the update. The datatable is based on a join so I don't know...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.