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

Concatenating data from more than one record of the same field

I need some ACCESS VB code to go thru one table that has multiple records for any given key and a 'Notes' field and then create another table with one record for the same record key, as the first table, that has a new 'Notes' field that has the notes for that key concatenated.
Mar 8 '07 #1
1 1206
MSeda
159 Expert 100+
I haven't tested the following code but it should be close to what you need. See what you can do with it and post back.

Expand|Select|Wrap|Line Numbers
  1. Dim mySQl As string
  2. Dim KeyRS as new adodb.recordset
  3. Dim NoteRs as new adodb.recordset
  4. Dim myNote as string
  5.  
  6. mySQL = “SELECT DISTINCT anygivenKEY FROM agTbl;”
  7.  
  8. KeyRS.Open mySQL
  9.  
  10. Do Until KeyRS.EOF
  11.  
  12. mySQL = “SELECT Notes FROM journalTBL WHERE [NoteKEY] = “ & keyRS.Fields(“anygivenKEY”) & “AND Not ISNull([Notes]);” 
  13.  
  14. NoteRS.open mySQL
  15.  
  16.     Do Until NoteRS.EOF
  17.     If isnull(myNote) then
  18.     myNote = noteRS.Fields(“Notes”)
  19.     Else
  20.     MyNote = MyNote & “, “ & noteRS.Fields(“Notes”)
  21.     Endif
  22.     NoteRS.movenext
  23.     Loop
  24.  
  25. NoteRS.Close
  26.  
  27. mySQL = “INSERT INTO noteTBL (noteKEY, concNote) VALUES (“ & keyRS.Fields(“anygivenKEY”) & “, ‘” & myNote & “’);”
  28. docmd.runSQl mySQL
  29.  
  30. KeyRS.movenext
  31. Loop
  32.  
  33. KeyRS.Close
  34.  
  35.  
Mar 8 '07 #2

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

Similar topics

2
by: Doug Shokes | last post by:
All, Given multiple records with identical values in all fields except a single varchar field, is there an efficient query that will group the records into a single record and concatenate the...
32
by: Neil Ginsberg | last post by:
We're using SQL Server 7 with an Access 2000 MDB as a front end with ODBC linked tables. I recently created a new set of tables for the app, and users are complaining that unsaved data is being...
32
by: Neil Ginsberg | last post by:
We're using SQL Server 7 with an Access 2000 MDB as a front end with ODBC linked tables. I recently created a new set of tables for the app, and users are complaining that unsaved data is being...
16
by: Dixie | last post by:
I have a problem using Dev Ashish's excellent module to concatenate the results of a field from several records into one record. I am using the code to concatenate certain awards onto a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
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
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...

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.