Solved

combining string

Posted on 2002-04-04
6
172 Views
Last Modified: 2012-05-04
hi everybody,

i have a problem here.. about vb and database (MS Access)

okay, in my database, i have this kind of data
MyTable
id         PatternA           PatternB
1            a/1                b/1
1            b/2                b/2
1            dd/3              kl/3
1           dkaf/4              a/4
1            kjb/5              abcd/5
2           bb/1                 d/1
2            a/2                 def/2
2            bba/3                 c/3
...            ...               ....

okay, now i would like to put this thing in another table with another kind of arranging them, for example;

NewTable
id          PatA                          PatB
1       a/1b/2dd/3dkaf/4kjb/5    b/1b/2kl/3a/4abcd/5
2       bb/1a/2bba/3              d/1def/2c/3
..         ...                         ...

what i mean is, with the same id, all string in PatternA will be combine and put in PatA same as PatternB
i hope i explain it clearly.

got any idea?..

help in need;
FaRZ
0
Comment
Question by:FaRZ
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 6

Accepted Solution

by:
sharmon earned 50 total points
ID: 6920139
Here's one way...

Loop through your recordset and build the new rows to enter.

Assuming using ADO and you have already setup your connection, etc...

I wrote on the fly without anykind of test, hopefully you can make it work as you need...

Regards,
Shannon

rs.Open "SELECT ID, PatternA, PatternB FROM MyTable ORDER BY ID ASC"

Dim lngID As Long
Dim strPatA As String
Dim strPatB As String
Dim strSQL As String

lngID = -1

Do While Not rs.EOF

    If rs("ID").Value <> lngID Then

        If lngID <> -1 Then
           
            strSQL = "INSERT INTO MyNewTable (ID, PatA, PatB) VALUES ("
            strSQL = strSQL & lngID & ", '" & Replace(strPatA, "'", "''")
            strSQL = strSQL & "', '" & Replace(strPatB, "'", "''") & "')"
            cn.Execute strSQL
       
        End If

        strPatA = ""
        strPatB = ""
        lngID = rs("ID").Value
   
    End If
   
    strPatA = strPatA & rs("PatternA").Value
    strPatB = strPatB & rs("PatternB").Value

    rs.MoveNext
 
Loop

rs.Close
0
 
LVL 52

Expert Comment

by:Ryan Chong
ID: 6920149
For research: Just wonder if can retrieve the records wanted with a single SQL..

<listening..>
0
 
LVL 6

Expert Comment

by:sharmon
ID: 6920171
ryancys,

I was thinking the same thing, but nothing popped in my head quickly since the layout he provided had no real way to assure the data in the original recordset was in an order that would make it maybe possible.  Although I'd like to see it that way...maybe someone else has some more ideas.

Shannon
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 6921534
Please maintain your open questions:

Questions Asked 12
Last 10 Grades Given A A A A C C B  
Question Grading Record 7 Answers Graded / 7 Answers Received

Thanks,
Anthony
0
 

Author Comment

by:FaRZ
ID: 6922510
thanks sharmon..

it works and helps me a lottt..

FaRZ
0
 
LVL 6

Expert Comment

by:sharmon
ID: 6923057
Your welcome, glad I could help.

Shannon
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month5 days, 19 hours left to enroll

626 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question