Solved

Convert row to column in Acsess

Posted on 2014-10-19
5
284 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
  • 2
  • 2
5 Comments
 
LVL 29

Accepted Solution

by:
IrogSinta earned 500 total points
Comment Utility
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 47

Expert Comment

by:Dale Fye (Access MVP)
Comment Utility
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
Comment Utility
@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
Comment Utility
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
Comment Utility
@IrogSinta
That did exactly what I wanted it! Thanks for your help...
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This article describes some very basic things about SQL Server filegroups.
Read about achieving the basic levels of HRIS security in the workplace.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now