473,442 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Update Table Snag

I have two tables. The one I am updating has 11 fields (CustNbr (primary), comments, comments1, comment2, etc up to 10).

The other table has only 2 fields (Custnbr, comments) and there can be one custnbr with different comments (hence the 10 fields of comments)

Here's what I have but it's updating ALL the records with the same thing:

Dim rs As Recordset
Dim rst As Recordset
Dim sql As String
Dim str As String
Dim strqry As String
Dim icount As Integer

sql = "Select * from CommentTest"
Set rs = CurrentDb.OpenRecordset(sql)

str = "SELECT comments.Field1 AS Custnbr, [comments]![Field4] & [comments].[field5] & [comments].[field6] & [comments].[field7] AS Comments " & _
"FROM comments GROUP BY comments.Field1, [comments]![Field4] & [comments].[field5] & [comments].[field6] & [comments].[field7] "
Set rst = CurrentDb.OpenRecordset(str)

While Not rst.EOF
For icount = 1 To 10
strqry = "where " & rs(0) & " = " & rst(0) & " "
sql = "UPDATE [commentTest] SET [comment" & icount & "] = '" & rst(1) & "' " & strqry & ""
'MsgBox sql
CurrentDb.Execute (sql)
Next icount
rst.MoveNext
Wend

rs.Close
rst.Close
Set rs = Nothing
Set rst = Nothing

My eyes are tired and I'm about to give up. Any help is appreciated.
Aug 31 '07 #1
1 1040
Rabbit
12,516 Expert Mod 8TB
I only looked at the WHERE clause so I can't say if the rest of your code is correct but:
Expand|Select|Wrap|Line Numbers
  1. strqry = "where " & rs(0) & " = " & rst(0) & " "
You're telling it to update if rs(0) is equal to rst(0), which will be true for every single record if the first record in rs(0) equals any of the first 10 records in rst(0).
Aug 31 '07 #2

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

Similar topics

1
by: mstjean | last post by:
Beginning to look at the mechanics of deployment at our site for our new project, our first in .NET. Management insists all apps will run from the network, not from desktops and we've managed to...
7
by: Dave | last post by:
I have 2 tables, one with names, and another with addresses, joined by their CIVICID number (unique to the ADDRESSINFO table) in Oracle. I need to update a field in the NAMEINFO table for a...
8
by: Lauren Quantrell | last post by:
In VBA, I constructed the following to update all records in tblmyTable with each records in tblmyTableTEMP having the same UniqueID: UPDATE tblMyTable RIGHT JOIN tblMyTableTEMP ON...
1
by: Andrew | last post by:
Hello, Rather complicated one im afraid.. (well for me anyway!) Background on this one is that I have inherited a system that needs some modification, have some basic sql knowledge but fear i've...
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...
16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
5
by: PAUL | last post by:
Hello, I have 2 tables with a relationship set up in the dataset with vb ..net. I add a new record to the parent table then edit an existing child record to have the new parent ID. However when I...
3
by: Michel Esber | last post by:
Hi all, DB2 V8 LUW FP 15 There is a table T (ID varchar (24), ABC timestamp). ID is PK. Our application needs to frequently update T with a new value for ABC. update T set ABC=? where ID...
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
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
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.