dcsimg
Results 1 to 9 of 9

Thread: [RESOLVED] VB6 - Copy a table's columns to another table Within the same database

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2007
    Posts
    341

    Resolved [RESOLVED] VB6 - Copy a table's columns to another table Within the same database



    Hi everyone,
    I have two tables "TableA" and "TableB" TableA has 9 columns and TableB has 4 columns. I created a new table "TableC" with 5 columns. I want to copy 3 columns from TableA(with its data) to TableC and Copy one column from TableB to TableC . I added a new column to TableC and this column will only contain the indexes of a column from TableA. After copying those columns, I want to delete the copied columns from TableA and TableB. My final objective is to make two of the fields(columns) in TableC a foreign key to TableA.
    All of these tables reside within the same MS Access database.
    What is my best code approach to accomplish this objective?
    Thanks.
    GiftX.

  2. #2
    Super Moderator Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: VB6 - Copy a table's columns to another table Within the same database

    Moved to database development

    Are you using Access VBA?
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2007
    Posts
    341

    Re: VB6 - Copy a table's columns to another table Within the same database

    I am using VB 6.0
    GiftX

  4. #4
    Super Moderator Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: VB6 - Copy a table's columns to another table Within the same database

    Try something like
    Code:
    SELECT *
    INTO NewTablenAME
    FROM OldTableName
    WHERE 1=2
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2007
    Posts
    341

    Re: VB6 - Copy a table's columns to another table Within the same database


    Hi Hack,
    thanks for your input. I am not copying all the old table content. I am only copying specific fields. And after copying the fields to my new table, I want to delete those fields from the old table.

    And yes, a while back, I set up a recurring monthly donation to the "Save Anna" venture, through Paypal.
    Thanks.
    GiftX.

  6. #6
    Super Moderator Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: VB6 - Copy a table's columns to another table Within the same database

    What I posted will copy the structure and not the content.

    This code copies the structure of OldTableName and creates a new table called NewTableName with identical structure. If you don't want all fields, don't so a SELECT *
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2007
    Posts
    341

    Re: VB6 - Copy a table's columns to another table Within the same database

    Thanks again.
    I don't need the structure. I have already created my new table. I simply want to populate it using data from the other two tables.
    Thanks.
    Gift.

  8. #8
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,692

    Re: VB6 - Copy a table's columns to another table Within the same database

    Select the fields you want from Table1 and Table2 into Table3.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2007
    Posts
    341

    Re: VB6 - Copy a table's columns to another table Within the same database

    Thanks everyone for your input. I am just gonna go ahead and use a query design and populate the new table.
    Gift

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width