Solved

Convert row to column in Acsess

Posted on 2014-10-19
5
298 Views
Last Modified: 2014-10-24
I'm exporting from a Pervasive database to a PostgreSQL from one ERP to another ERP system using an Access database. I'm linking to both databases using ODBC.

In the attached Access database I have a table from the Pervasive database that contains one row of data for the Fiscal Calendar/Periods.

I want to convert the table rows to 2 columns, the field name should be a column and the field data should be another column.

I also want to do the same for the query "fiscal periods in roman calendar"

Is this possible?
ee-database.accdb
0
Comment
Question by:Gerhardpet
[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
  • 2
  • 2
5 Comments
 
LVL 29

Accepted Solution

by:
IrogSinta earned 500 total points
ID: 40390227
Here's one way:
Create a table called CalendarPeriod with a Text field called Period and a Number field called PeriodDate.
Create a module, add the following code and run it.
Private Sub GrabFromTable()
    Dim rsSrc As Recordset
    Dim rsTgt As Recordset
    
    Set rsTgt = CurrentDb.OpenRecordset("CalendarPeriods")
    Set rsSrc = CurrentDb.OpenRecordset("CTRL_PERIODS")
    
    'iterate from the 3rd to the last field in CTRL_PERIODS and append to target table
    For i = 2 To rsSrc.Fields.Count - 1
        
        rsTgt.AddNew
        rsTgt!Period = rsSrc.Fields(i).Name
        rsTgt!PeriodDate = rsSrc.Fields(i)
        rsTgt.Update
    
    Next
    
    rsTgt.Close
    rsSrc.Close
    Set rsTgt = Nothing
    Set rsSrc = Nothing
    
End Sub

Open in new window

You can do something similar for the query.

Ron
0
 
LVL 48

Expert Comment

by:Dale Fye
ID: 40390370
on my iPad, so I cannot open your file.

A normalizing query would normally look something like:

SELECT "Column1" as Description, [Column1] as ColValue
FROM yourTable WHERE [Column1] IS NOT NULL
UNION ALL
SELECT "Column2" as Description, [Column2] as ColValue
FROM yourTable WHERE [Column2] IS NOT NULL

This, of course assumes that the actual Values in [Column1] and [Column2] are of the same data type.
0
 
LVL 1

Author Comment

by:Gerhardpet
ID: 40394346
@IrogSinta
That worked perfectly..

The only thing left is to run the module from a form/button and also a confirmation message that is done running.

Can you help with that?
0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 40394641
Well then just insert that code in the OnClick event of a button that you place on a form.  At the end of the code, just simply add a message box like so:

MsgBox "Done"
0
 
LVL 1

Author Closing Comment

by:Gerhardpet
ID: 40403447
@IrogSinta
That did exactly what I wanted it! Thanks for your help...
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
Steps to create a PostgreSQL RDS instance in the Amazon cloud. We will cover some of the default settings and show how to connect to the instance once it is up and running.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

617 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