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

Update statement doesn't update

Hello,

I'm kind of newby in VBA/SQL in access.

I'm trying to write a code that sums several columns and the result should be "updated" to a Total record.

I get no error message, but it doesn't work.

What can be wrong?

Here's part of the code.


Expand|Select|Wrap|Line Numbers
  1.     sqlselect = "SELECT * From 12MonthsTemp"
  2.     Set objrs = conn.Execute(sqlselect)
  3.     If (objrs.EOF <> True) Then
  4.         nrows = objrs.GetRows
  5.  
  6.         For i = 0 To UBound(nrows, 2)
  7.             bdate = nrows(0, i)
  8.             edate = nrows(1, i)
  9.             amnt = nrows(3, i)
  10.  
  11.             For j = 8 To 147
  12.                 SumRws = SumRws + nrows(j, i)
  13.             Next j
  14.  
  15.             tableupdate = "UPDATE 12MonthsTemp SET [Total Recognition]= " & SumRws & " WHERE ([Begin Date]='" & bdate & "') AND ([End Date]='" & edate & "') AND ([Invoice Amount]=" & amnt & ");"
  16.             conn.Execute (tableupdate), NumOfRec, dbFailOnError
  17.             Debug.Print NumOfRec & " records were updated."
  18.             SumRws = 0
  19.         Next
  20.     End If
  21.  
Any help should be appreciated.
Jul 19 '11 #1

✓ answered by NeoPa

Serge:
I use the DoCmd.RunSQL but I get this message "You are about to update 0 rows".
This means the criteria you have specified matches no records. I suggest you check your data.

PS. Assuming all the names used are correct, the SQL you posted is formatted perfectly OK.

13 5289
Rabbit
12,516 Expert Mod 8TB
If those date fields are actually date fields, you need to specify that they're dates using hash (#) symbols, not single quotes (').
Jul 19 '11 #2
Thank you for your response, but it still doesn't update the Total Recognition field...maybe I need another approach?
Jul 21 '11 #3
Rabbit
12,516 Expert Mod 8TB
Did you have the code output the update statement and seeing if you can manually run it?
Jul 21 '11 #4
NeoPa
32,556 Expert Mod 16PB
Please check out Debug SQL String before continuing with this question.
Jul 23 '11 #5
Expand|Select|Wrap|Line Numbers
  1. UPDATE 12MonthsTemp SET [Total Recognition]= -134255.64 WHERE ([Begin Date]=#5/1/2007#) AND ([End Date]=#4/30/2008#) AND ([Invoice Amount]=-11187.97);
Jul 25 '11 #6
Rabbit
12,516 Expert Mod 8TB
And does that run when you do it manually?
Jul 25 '11 #7
Rabbit, I'm not sure what do you mean by "manually run it". I use the DoCmd.RunSQL but I get this message "You are about to update 0 rows".
I also run it by hiting F8 key, with the same result:No error message, but not updating the table....
Jul 25 '11 #8
Rabbit
12,516 Expert Mod 8TB
I mean create a new query, paste in the SQL, and run it. If there are errors, then your dynamic SQL string is incorrectly syntaxed and the error message will give you an idea as to what the problem is. If there is no error message, but it doesn't do what you want, then there isn't anything syntactically wrong but something else is wrong with the string, perhaps with how the filters are being set up.
Jul 25 '11 #9
NeoPa
32,556 Expert Mod 16PB
Serge:
I use the DoCmd.RunSQL but I get this message "You are about to update 0 rows".
This means the criteria you have specified matches no records. I suggest you check your data.

PS. Assuming all the names used are correct, the SQL you posted is formatted perfectly OK.
Jul 25 '11 #10
Rabbit
12,516 Expert Mod 8TB
What you should do is start with a select query and once you can consistently select the record you want, make the update query's where clause the same as your select query's where clause.
Jul 25 '11 #11
NeoPa, you were right.

I changed the criteria and it worked like a charm.

Thank you, very much!
Jul 26 '11 #12
Thank you Rabbit for your response, it seems that the "Where" criteria was ambiguos or something.
Change it and it work!
Jul 26 '11 #13
NeoPa
32,556 Expert Mod 16PB
I'm very pleased you managed to get it sorted :-)
Jul 27 '11 #14

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

Similar topics

6
by: David Shorthouse | last post by:
Hello folks, I have a problem with an update query on an asp not updating the table in an Access db. The code runs, I have no errors, but when I examine the table, nothing was updated. The query...
8
by: pb648174 | last post by:
I have a single update statement that updates the same column multiple times in the same update statement. Basically i have a column that looks like .1.2.3.4. which are id references that need to...
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...
5
by: Wing | last post by:
Hi all, I am writing a function that can change the value "Quantity" in the selected row of MS SQL table "shoppingCart", my code is showing below ...
3
by: Munno | last post by:
Hi All, I am not so proficient in SQL and seek your help. I have a column by the name of Mask in a table, which has text eg. (YYYYYYYNNNNYYYYYYYYYNNYYYY). I wanted to update one particular...
0
by: Munno | last post by:
Hi All, I am not so proficient in SQL and seek your help. I have a column by the name of Mask in a table, which has text eg. (YYYYYYYNNNNYYYYYYYYYNNYYYY). I wanted to update one particular...
19
by: Steve | last post by:
ASP error number 13 - Type mismatch with SELECT...FOR UPDATE statement I got ASP error number 13 when I use the SELECT...FOR UPDATE statement as below. However, if I use SELECT statement without...
10
by: Luigi | last post by:
Hello all! I'm a newbie in PHP. I have written a short script that tries to update a SQLite database with the user data. It is pretty simple, something like this: <?php $sqlite =...
7
by: BONES7714 | last post by:
Hello, This is my first post to any sort of forum although I've used them to learn the very little Access/VBA that I know so please forgive my ignorance. I work for the National Guard as Combat...
14
by: omar999 | last post by:
hi guys im using classic asp and sql server 05 - and my web form submits an update statement which in result updates a sql table. my question is, is there a way to force an update statement to...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...

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.