Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7021003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:23:33+00:00 2026-05-27T23:23:33+00:00

I have inherited a old access database that includes a table with data organised

  • 0

I have inherited a old access database that includes a table with data organised like this:

+-------+--------+-------------+-------------+-------------+----------------+
| Code  |  Year  |  Category1  |  Category2  |  Category3  |  ... etc ...   |
+-------+--------+-------------+-------------+-------------+----------------+
| A     |  2011  |          1  |          4  |         12  |                |
| A     |  2012  |          5  |          33 |         24  |                |
| B     |  2012  |          4  |          11 |         76  |                |
+-------+--------+-------------+-------------+-------------+----------------+

I need to change this (the actual table has lots of columns) to the following structure:

+-------+--------+-------------+--------+
| Code  |  Year  |  Cat        |  Value |
+-------+--------+-------------+--------+
| A     |  2011  |  Category1  | 1      |
| A     |  2011  |  Category2  | 4      |
| A     |  2011  |  Category3  | 12     |
| A     |  2012  |  Category1  | 5      |
| A     |  2012  |  Category2  | 33     |
| A     |  2012  |  Category3  | 24     |
| B     |  2012  |  Category1  | 4      |
| B     |  2012  |  Category2  | 11     |
| B     |  2012  |  Category3  | 76     |
+-------+--------+-------------+--------+

Is it possible to do this via some automatic conversion in MS Access (I have version 2010)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T23:23:34+00:00Added an answer on May 27, 2026 at 11:23 pm

    You can use a union query:

    SELECT a.* INTO NewTable FROM (
      SELECT [Code], [Year], "Category1" As Cat, Category1 As CatVal FROM MyTable
      UNION ALL
      SELECT [Code], [Year], "Category2" As Cat, Category2 As CatVal FROM MyTable
      UNION ALL
      <...> ) As a
    

    You might like to eliminate the reserved word “Year” while you are at it : http://support.microsoft.com/kb/321266

    If you have a lot of categories, you can use VBA to make life easier, for example:

    Sub UnionSQL(ArrayColCommonWord As String, TableName As String)
    Dim db As Database
    
    Set db = CurrentDb
    
    For Each fld In db.TableDefs(TableName).Fields
        If Left(fld.Name, Len(ArrayColCommonWord)) <> ArrayColCommonWord Then
            sSQL1 = sSQL1 & ",[" & fld.Name & "]"
        End If
    Next
    
    sSQL1 = "SELECT " & Mid(sSQL1, 2)
    
    For Each fld In db.TableDefs(TableName).Fields
        If Left(fld.Name, Len(ArrayColCommonWord)) = ArrayColCommonWord Then
            sSQL = sSQL & vbCrLf & "UNION ALL" & vbCrLf
            sSQL = sSQL & sSQL1 & ",'" & fld.Name & "' As " & ArrayColCommonWord _
                & ",[" & fld.Name & "] As " & ArrayColCommonWord & "Val"
            sSQL = sSQL & vbCrLf & "FROM [" & TableName & "]"
        End If
    Next
    
    Debug.Print Mid(sSQL, 14)
    ''This will fail if there is an existing query
    db.CreateQueryDef ArrayColCommonWord, Mid(sSQL, 14)
    
    DoCmd.OpenQuery ArrayColCommonWord, acViewDesign
    
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have inherited a very old database that needs some data to be updated.
I have inherited some really old VC6.0 code that I am upgrading to VS2008
I have inherited a 20-year-old interactive command-line unix application that is no longer supported
I have inherited an old application that stores a zip file in a database
I have inherited an old crusty PHP application , and I'd like to refactor
I have inherited a VB6/Access application that we have developed and sold for many
I have inherited some old code and need to convert to the latest schema
I inherited a database from an old system we have, in which (among other
I have an old piece of code that I want to upgrade it to
I have recently inherited the sad task of recovering data from an old MSSQL

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.