Solved

combining string

Posted on 2002-04-04
6
170 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 51

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
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!

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
passing parameter in sql procedure 9 68
VBA: Select SQL query based on a config Sheet v2 11 52
Problem to line 23 73
Remove Exif Orientation before adding image to db 9 38
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.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

740 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