Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

combining string

Posted on 2002-04-04
6
Medium Priority
?
175 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
6 Comments
 
LVL 6

Accepted Solution

by:
sharmon earned 200 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 54

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

963 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