473,408 Members | 1,876 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,408 software developers and data experts.

Update query not working.

44
Hi all;
Can anybody tell me why the following doesn't work in my update query? I've had a good look around online but there's not much help out there:

Expand|Select|Wrap|Line Numbers
  1. nz(DSum("[AcctBalance]","[tblAccounts]","[tblCustomers]![CustID]=[tblAccounts]![CustID]"))
It's in the "Update To:" part of an existing field in the Access query grid. I click the "Run Query" button and nothing happens, the fields aren't updated and there's not even an error message. I even tried this string as a calculated field in a select query (to try it out) and again, blank fields and no error message.

Any ideas?
Thanks!
Apr 3 '09 #1
7 2843
NeoPa
32,556 Expert Mod 16PB
It has no way of determining what you mean by "[tblCustomers]![CustID]" within the DSum() function call.
Apr 3 '09 #2
Whizzo
44
I'd have thought it would interpret "[tblCustomers]![CustID]" as referring to the CustID field in the tblCustomers table, no? Both the tables I'm working on are pulled up in the top half of the query builder, and there's a one-to-many link in place between the two by CustID.

Sometimes it seems to me that Access has stuffed its fingers in its ears and turned the other way!
Apr 3 '09 #3
NeoPa
32,556 Expert Mod 16PB
@Whizzo
I'm afraid that says more about your understanding at this stage than Access's shortcomings. I do appreciate that things can get complicated in database work, but this behaviour is perfectly logical.

The place where it falls down is within a DSum() function call. Access (within the DSum() function) cannot reasonably be expected to realise that the parameters passed should be cross referenced with any SQL from near the calling code.

The second parameter is the Domain, and this defines to the function, the scope of where it can reference data. If you need more than one recordset to be included (available) then you need a QueryDef defined that incorporates both, and pass that as the Domain parameter.

I hope this helps you understand the issue a little better.
Apr 3 '09 #4
ChipR
1,287 Expert 1GB
If that's in your Update To field, and you aren't getting any results or any errors, what are you selecting the records to update based on?
Apr 3 '09 #5
Whizzo
44
I was hoping that the fields would be updated to the figure returned by the Dsum function but no luck. The exact same string on the On Current event in a form sets the value of a control perfectly, simply using me!control = ... in VB. I was under the inpression that:

Expand|Select|Wrap|Line Numbers
  1. DSum("[AcctBalance]","[tblAccounts]","[tblCustomers]![CustID]=[tblAccounts]![CustID]")
in the Update To bit of the design grid would perform at least roughly the same function. i.e. "Add up the AcctBalance figures in tblAccounts where the CustID number is the same as the CustID of this target field." I think I'll just have to scroll through all 35,000 records in the form and let the code in the form do the work! Can anyone recommend a decent book on the subject? Everything else out there seems to be either for pros or simpletons, is there anything that covers the middle ground?
Apr 3 '09 #6
ChipR
1,287 Expert 1GB
If you want to use an update query, try the pure SQL approach rather than using DSUM. Make a Group By query on tblAccounts grouped on CustID with CustID and Sum(AcctBalance). Then write your query to update your other table to the totals in that query.

Your other option of using code would be done much easier by running a function once that opened a recordset and stepped through it, updating each record, rather than having to scroll through all the records in a form.

Come to think of it, why are you storing this calculated value in a table, rather than using the result of the group by query so that it is up-to-date when you need it?

I found Beginning Access 2000 VBA (wrox) to be very helpful starting out, but I'm not sure exactly what subject you are looking for.
Apr 3 '09 #7
Whizzo
44
I'm not calculating this on the fly because the data in the DB is only a snapshot, read-only. The findings will be used to make updates straight to the mainframe somewhere in Denmark. I'm trying to populate a flat table which will generate a report, rather than relying on queries to come up with report data. I found a kind of alternative to scrolling through the records in the end, I put GoToRecord,next on the On Timer event of the form and set it to 20ms. The computer is grunting and straining and the other monitor is a bit of a blur but it seems to be working!

I'll order that book I think, maybe there's one on SQL too. These forums are great for solving immediate problems but to gain a broader understanding it's going to have to be books, books, books!
Apr 3 '09 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Surendra | last post by:
I have this query that I need to use in an Update statement to populate a field in the table by the value of Sq ---------------------------------------------------------------------------- Inline...
17
by: kalamos | last post by:
This statement fails update ded_temp a set a.balance = (select sum(b.ln_amt) from ded_temp b where a.cust_no = b.cust_no and a.ded_type_cd = b.ded_type_cd and a.chk_no = b.chk_no group by...
10
by: Randy Harris | last post by:
I imported records into a table, later found out that many of them had trailing spaces in one of the fields. If I'd caught it sooner, I could have trimmed the spaces before the import. This...
3
by: Greg Strong | last post by:
Hello All, Is the only solution to an update query which requires the records in a certain order to dump the records into a temp table in the required order, then do the update query? I've...
7
by: aaron.kempf | last post by:
team so i have a nice little list in sharepoint.. about 15k items i've got the simplest little join statement in access; and im trying to UPDATE the sharepoint list via an access query. so...
3
by: Shapper | last post by:
Hello, I have created 3 functions to insert, update and delete an Access database record. The Insert and the Delete code are working fine. The update is not. I checked and my database has all...
11
by: ZafT | last post by:
Hi all - thanks in advance for any help. I am trying to write a simple update script. In fact, I am re-using code that I've used before (successfully) but I can't figure out why it is not...
8
by: Andi Clemens | last post by:
Hi, I want to update our DNS servers periodically with some IP addresses. But I don't know how to do this. I searched the Internet quite a while but I haven't found a good example how to do...
5
by: abhilashcashok | last post by:
hi guys, my prblem is that I cannot update sql query against MS ACCESS using C#. Everytime wen i do so, i got an exception (at runtime) as 'UPDATE syntax not correct'. I don find any error in my...
12
by: praveenkrg | last post by:
my update query is not working properly! $mgroupname=$_GET; //echo $mgroupname; ///query for checking userg_id $result=mysql_query("SELECT * FROM group WHERE userg_name ='$mgroupname'");...
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.