Results 1 to 2 of 2
  1. #1
    mradel is offline Novice
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Oct 2010
    Posts
    1

    Using queries to create new table

    I have a table as follows:



    Name: Addr: City: State:
    1 Mike 123 Pine Mpls MN
    2 John 25 Jones LA CA
    3 Bill 9 North Dover IA

    Is there a way to change the table as follows?

    Name: Data:
    1 Mike 123 Pine
    1 Mike Mpls
    1 Mike MN
    2 John 25 Pine
    2 John LA
    2 John CA
    3 Bill 9 North
    3 Bill Dover
    3 Bill IA

    Is there an easy way to complete this type of conversion? I have a table that has 12 feilds and 806 records that I need to convert in the the new table format.

    Thanks for the help.

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    try making a new table with 2 fields in it, as you stated above. then loop your old table...

    for instance, something like:
    Code:
    dim rs as recordset
    set rs=currentdb.openrecordset("table")
    
    dim i as long
    dim sname as string
    
    with rs
       .movelast
       .movefirst
          do until .eof
             for i=0 to rs.fields.count-1
                if not rs.fields(i).name="name" then
                   currentdb.execute "INSERT INTO newtable ( name, data ) " & _
                                     "VALUES ( '" & sname & "', '" & rs.fields(i) & "' )"
                else
                   sname = rs!name
                end if
             next i
                      .movenext
          loop
    end with
    
    rs.close
    
    set rs=nothing
    using that many append query actions at the speed that vba code executes may be problematic for large data sets, but it's obviously worth a try. backup your file before trying this, if you do. with only 800 records to do, I doubt it'll cause an issue.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Create a static table
    By Alexandre Cote in forum Programming
    Replies: 2
    Last Post: 09-13-2010, 10:59 AM
  2. Create Table If Not Exists
    By jp2access in forum Queries
    Replies: 7
    Last Post: 07-14-2009, 12:49 PM
  3. Using VBA create a new table from an existing table
    By KramerJ in forum Programming
    Replies: 0
    Last Post: 03-25-2009, 04:07 PM
  4. Auto-Create a Table
    By Mxcsquared in forum Forms
    Replies: 3
    Last Post: 01-28-2006, 11:36 PM
  5. automatically create queries
    By GEORGIA in forum Programming
    Replies: 8
    Last Post: 01-23-2006, 02:35 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums