PC Review


Reply
Thread Tools Rate Thread

Combine Subsequent Table Records

 
 
David Frazell
Guest
Posts: n/a
 
      24th May 2004
How can I combine two subsequent records from Table1 into a single record in
Table2?

Table1 has two fields, Unique Record ID and Text String.

For example:
ID Text
1 Text string record 1
2 Text string record 2
3 Text string record 3
4 Text string record 4
....
n Text string record n
n+1 Text string record n+1

The result in Table 2 needs to be:
1 Text string record 1 Text string record 2
2 Text string record 3 Text string record 4
3 Text string record 5 Text string record 6
....

Thanks,
Dave F.


 
Reply With Quote
 
 
 
 
Nikos Yannacopoulos
Guest
Posts: n/a
 
      24th May 2004
David,

Try something like this:

Sub populate_table()
Dim rs1 As DAO.Recordset
Dim rs2 As DAO.Recordset
Dim cnt As Long

cnt = 1
Set rs1 = CurrentDb.OpenRecordset("Table1")
Set rs2 = CurrentDb.OpenRecordset("Table2")
rs1.MoveFirst
On Error GoTo sub_exit
Do Until rs1.EOF
rs2.AddNew
rs2.Fields(0) = cnt
rs2.Fields(1) = rs1.Fields(1)
rs1.MoveNext
rs2.Fields(2) = rs1.Fields(1)
rs1.MoveNext
rs2.Update
cnt = cnt + 1
Loop

sub_exit
rs1.Close
Set rs1 = Nothing
rs2.Close
Set rs2 = Nothing

End Sub

You will need to add DAO to your references, if not already there. From the
VB window go Tools > References, and add Microsoft DAO 3.x (3.51 for A97,
3.6 for A2K or later).

HTH,
Nikos

"David Frazell" <(E-Mail Removed)> wrote in message
news:TKCdnf_9wq-HvSzdRVn-(E-Mail Removed)...
> How can I combine two subsequent records from Table1 into a single record

in
> Table2?
>
> Table1 has two fields, Unique Record ID and Text String.
>
> For example:
> ID Text
> 1 Text string record 1
> 2 Text string record 2
> 3 Text string record 3
> 4 Text string record 4
> ...
> n Text string record n
> n+1 Text string record n+1
>
> The result in Table 2 needs to be:
> 1 Text string record 1 Text string record 2
> 2 Text string record 3 Text string record 4
> 3 Text string record 5 Text string record 6
> ...
>
> Thanks,
> Dave F.
>
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Combine two records in a table clk Microsoft Access Form Coding 1 10th Sep 2010 06:23 PM
Combine records in a table slickdock Microsoft Access VBA Modules 5 11th Aug 2009 08:16 PM
How to combine two tables and dedup records from one table =?Utf-8?B?Y2FicmFkbGV5MTE=?= Microsoft Access Queries 2 25th Apr 2006 05:25 AM
Do I have to have equal number of records in each table to combine them? david.isaacks@mail.va.gov Microsoft Access Queries 14 20th Apr 2006 11:27 PM
Creating a new table to combine records ie. Mr and Mrs. =?Utf-8?B?THlubiBDYXJsdG9u?= Microsoft Access 2 3rd Dec 2004 08:03 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:49 AM.