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. -
sqlselect = "SELECT * From 12MonthsTemp"
-
Set objrs = conn.Execute(sqlselect)
-
If (objrs.EOF <> True) Then
-
nrows = objrs.GetRows
-
-
For i = 0 To UBound(nrows, 2)
-
bdate = nrows(0, i)
-
edate = nrows(1, i)
-
amnt = nrows(3, i)
-
-
For j = 8 To 147
-
SumRws = SumRws + nrows(j, i)
-
Next j
-
-
tableupdate = "UPDATE 12MonthsTemp SET [Total Recognition]= " & SumRws & " WHERE ([Begin Date]='" & bdate & "') AND ([End Date]='" & edate & "') AND ([Invoice Amount]=" & amnt & ");"
-
conn.Execute (tableupdate), NumOfRec, dbFailOnError
-
Debug.Print NumOfRec & " records were updated."
-
SumRws = 0
-
Next
-
End If
-
Any help should be appreciated.
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
If those date fields are actually date fields, you need to specify that they're dates using hash (#) symbols, not single quotes (').
Thank you for your response, but it still doesn't update the Total Recognition field...maybe I need another approach?
Did you have the code output the update statement and seeing if you can manually run it?
- UPDATE 12MonthsTemp SET [Total Recognition]= -134255.64 WHERE ([Begin Date]=#5/1/2007#) AND ([End Date]=#4/30/2008#) AND ([Invoice Amount]=-11187.97);
And does that run when you do it manually?
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....
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.
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.
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.
NeoPa, you were right.
I changed the criteria and it worked like a charm.
Thank you, very much!
Thank you Rabbit for your response, it seems that the "Where" criteria was ambiguos or something.
Change it and it work!
NeoPa 32,556
Expert Mod 16PB
I'm very pleased you managed to get it sorted :-)
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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
...
|
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...
|
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...
|
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...
|
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 =...
|
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...
|
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...
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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: 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,...
|
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...
|
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,...
| |