Solved

Convert row to column in Acsess

Posted on 2014-10-19
5
286 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
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 47

Expert Comment

by:Dale Fye (Access MVP)
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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

948 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

22 Experts available now in Live!

Get 1:1 Help Now