Solved

combining string

Posted on 2002-04-04
6
171 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Technology Partners: 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!

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
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…

752 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