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

Where in Update Statement Not Working--Updating All Records Instead

Hello,

I could use a little help trying to figure this one out--I would greatly appreciate it.

I'm using an UPDATE statement in VBA to update a table. Typically, this statement should only affect one record. For some reason, it's updating all the records in the table. I'm assuming my WHERE statement is wrong. Here's a short version of the code (all variables in the SQL string are integers:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Set cn = New ADODB.Connection
  3. Set rs = New ADODB.Recordset
  4. Dim recint As Integer
  5. strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbLocation
  6.  
  7. cn.Open strConnection
  8.  
  9. strSQL = "UPDATE tblTest SET Permission ='" & Permission & "', Order1 ='" & Order1 & "' WHERE CustID = RecID"
  10.  
  11. cn.Execute strSQL
  12. cn.Close
  13. Set cn = Nothing
  14. Set rs = Nothing
  15.  
  16.  
Oct 29 '10 #1
3 2350
NeoPa
32,556 Expert Mod 16PB
If [Permission] and [Order1] are both integers then the quotes (') you have around the values are superfluous. Only string literal values require quotes. I doubt that would explain all records being updated though.

That would pertain to the WHERE clause specifically. I assume that [CustID] and [RecID] are both fields in the table and are both numeric. I think we need to see some data though and an explanation of exactly what happens against that data - clearly explained.
Oct 29 '10 #2
Thank youfor the reply, NeoPa. I went back to the table and I did add a numeric field called [RecID] for debugging purposes. I removed this field and everything appears to work.

Thanks again.
Oct 29 '10 #3
NeoPa
32,556 Expert Mod 16PB
I'm glad it's now working, but confused how it can be if there is no longer a [RecID] field to match the SQL code in your WHERE clause. Probably no issue that I don't understand, but weird nevertheless.
Oct 29 '10 #4

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

Similar topics

3
by: Robert Mark Bram | last post by:
Hi All! I have the following two methods in an asp/jscript page - my problem is that without the update statement there is no error, but with the update statement I get the following error: ...
1
by: Google Mike | last post by:
I have one table of new records (tableA) that may already exist in tableB. I want to insert these records into tableB with insert if they don't already exist, or update any existing ones with new...
9
by: Muzamil | last post by:
hi For an unavoidable reason, I have to use row-by-row processing (update) on a temporary table to update a history table every day. I have around 60,000 records in temporary table and about 2...
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...
3
by: RDD | last post by:
Can somebody tell me how to get this to work? I have an Orders table and an OrderDetails table. The primary key of the OrderDetails table is a concatenation of OrderID and PlantID. If the...
6
by: FayeC | last post by:
I really need help figuring this out. i have a db with mostly text fields but 2. The user_id field is an autonumber (key) and the user_newsletter is a number (1 and 0) field meaning 1 yes the ...
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...
3
by: Antonio | last post by:
Can somebody tell my why the following procedure changes the data in the fields being updated to all the records in the database? private void updateRow(object source,...
2
by: lunas | last post by:
I have the following update statement bt it is not working, even after leaving it for 16 hrs it dint end and neighter any of the records got updated update allele_temp set ...
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: 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...
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?
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
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
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,...

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.