473,625 Members | 3,222 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Transpose Table in Current Database

4 New Member
{NeoPa - Admin} This question was split off from another thread (How can I transpose a table/query in Access?).

ADezii

I used your download and it worked quite well for me also but I only need the code to transpose the table and save it under the same name with transposed in the same database? Do I need to do this as a form or can I go ahead and select the macro directly? How would I make the changes required?
Jul 23 '17 #1
13 5410
ADezii
8,834 Recognized Expert Expert
Sorry Sally, didn't realize that you had already Posted in the Access/VBA Forum. Currently on Vacation but will return Thursday morning where I would be more than happy to revisit this question again. This is assuming, of course, that no one provides an answer before then.
Jul 24 '17 #2
ADezii
8,834 Recognized Expert Expert
I'm still on vacation without Access, but I figured that I would Post a few comments as well as an outline indicating how you can go about this process.
  1. The first point that you should be made aware of is that you have a 255 Fields/Columns restriction within an Access Table. This means that if you have greater than 255 Rows in you Table, the Data cannot be Transposed. You can, however, as in the Demo, created a Comma-Delimited Text File then Import it into Excel if > 255.
  2. That being said, here is my General Outline as to how I would Transpose the Data into another Table in the DB.
    1. We will assume your Table in named tblData. If the number of Rows in tblData is > 255, then the Transport simply cannot be done, and we will exit the Code. If the number of Rows is <= 255 then the Code will fall thru.
    2. Pass the number of Rows in tblData (lngNumOfRows), along with the Table Name in a Variable (strTblName) to a Public Function.
    3. This Function will dynamically create a Table named strTableName with lngNumOfRows Fields/Columns. For the sake of simplicity all Fields will be Type Text. If we had to analyze each Field in tblData then match the corresponding Field Type in tblData_Transpo sed, things would be complicated real fast. You can easily change the Types after the Table has been created then populated.
    4. A Recordset based on tblData is then created and a 2-Dimensional Array is then populated with the 1st Dimension representing the Row and the 2nd Dimension representing the Column. The Intersection of a Row and Column MyArray(Row, Column) in the Array will contain the Data for the Row/Column Intersection.
    5. We will create another Recordset based on the New Table (strTblName_Tran sposed) that will be used specifically to populate the newly created Table.
    6. We will now iterate thru MyArray using Nested For...Next Loops and basically swap the Row and Column Dimensions, populating strTblName_Tran sposed in the process.
  3. I know that this all sounds confusing, but I wanted to give you some indication as to ho this can be done. Work on it in the meantime and see what you can come up with until I return on Thursday morning.
Jul 25 '17 #3
ADezii
8,834 Recognized Expert Expert
This was a little more difficult than I thought, or it could be my first day back from Vacation! (LOL). In any event, I was able to Transpose Data in a Table following the Guidelines that I indicated in Post# 15. Rather than go into a detailed explanation of how this all works, I'll simply Attach the Demo that I have created for you, and should there be any questions, please feel free to ask.

P.S. One item that I forgot to incorporate into the Code was the checking of the 255 Field Limit in an Access Table. This point is very important but can easily be implemented within the existing Code. Good Luck with your Project.
Attached Files
File Type: zip Transpose With Array.zip (27.0 KB, 180 views)
Jul 27 '17 #4
Sally757
4 New Member
Good afternoon,

First, thank you for your time and expertise, they are appreciated. Your example was perfect.

I have a few general questions regarding the transpose code.

Is there any way the transpose could of been done using queries? Is there any other way besides a form to initiate the transpose code? Such as by running a query?

I want the database to import the data, add the new data to a table with the existing table, transpose the data and then report on the transposed data, is this the best method to do all this?

Again thank you.
Jul 29 '17 #5
NeoPa
32,567 Recognized Expert Moderator MVP
It is now possible again to respond to this thread. Please report any hijacks when you notice them.
Aug 7 '17 #6
ADezii
8,834 Recognized Expert Expert
Is there any way the transpose could of been done using queries?
The Transpose Code will work with any Object(s) from which a Recordset can be generated, namely: a Table, Query, or a SQL Statement.
Is there any other way besides a form to initiate the transpose code? Such as by running a query?
Any method that a Function Procedure can be called will work such as: an assignment expression, Function Call from an AutoExec Macro, etc. It could possibly be called within a Query via a Calculated Field, but this would not make much sense.
I want the database to import the data, add the new data to a table with the existing table, transpose the data and then report on the transposed data, is this the best method to do all this?
What I see as ideal would be to Transpose the Data while in its original state, then perform the Append and Report operations. Let's see if there are any other thoughts on your questions.
Aug 8 '17 #7
Sally757
4 New Member
Thank you again.

I would like the column headings to become the row headings in the transposed table. What is the best way to proceed with this? If you want an example I can send you one.
Sep 15 '17 #8
ADezii
8,834 Recognized Expert Expert
If you want an example I can send you one.
That is always a good idea, if only for clarification.
Sep 15 '17 #9
NeoPa
32,567 Recognized Expert Moderator MVP
Sally:
Is there any way the transpose could of been done using queries?
I imagine the question was more about using an alternative approach to the code than using a query as the input to the code ADezii. Something like a CrossTab query.
Sally:
Is there any other way besides a form to initiate the transpose code? Such as by running a query?
Bear in mind that a function may be called from a query but then it tends to be called for every line of the query - assuming it has a parameter passed that's a field from the query.
Sep 15 '17 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

4
2192
by: Robin Tucker | last post by:
Is there an sp_zzzzzz function to return the name of the current database? I would like to use this name as a variable in a stored procedure in order to create names for further databases (by appending a tag, such as MYDATABASE_BLOB001, ..._BLOB002 etc. Thanks.
0
1501
by: Nasos | last post by:
I want to have a command button which enables the user to make a copy of the current database, but without any records in it. Of course all the forms and reports will be intact. I want the old database to be given a different name so that it will be obvious that it is an archive copy and so that the new empty database will continue with the original name. Any help will be greatly appreciated. Thanks.
3
1724
by: Paul T. Rong | last post by:
Dear all, My aim is to compact and repair current database, I got the following code from http://www.mvps.org/access/general/gen0041.htm Option Compare Database ' ***** Code Start ***** Public Sub CompactDB()
4
31429
by: Ron St-Pierre | last post by:
I am using postgres 7.3.4 and need to be able to determine which database a query is being run in (from a script). pg_database lists databases but doesn't tell me which one is currently active. Is there a query I can use along the lines of: UPDATE tblUpdates SET xxx=1234 WHERE pg_current = TRUE; or UPDATE tblUpdates SET xxx=1234 WHERE pg_current = thisDBname; We have about 15 databases all set up identically and when the structure...
1
9062
by: Najm | last post by:
Hi All, I am facing this issue very frist time. I add a logical device as following: USE master GO EXEC sp_addumpdevice 'disk', 'AdvWorksData',
1
10710
by: Tiago Gigli | last post by:
Guys, 1st of all.. sorry about my english ok? Im from Brazil... Im trying to get a RS connecting through 2 databases with the query below: SELECT scar..osbalcao.numeroos, ccell.dbo.atrib_os.os FROM
1
1782
by: bb nicole | last post by:
Below is my interface for resume which need to post into database... I have did it all in one page and it already can send into database which the table name resume... But my letturer now want me to seperate it in to 4 pages( 1 page is for personnel particular, 1 page is for education, 1 page is for worl experience and so on). And it is need a next button to continue it, at last user need to click on post resume button and post to database....
1
7087
by: Shift4SMS | last post by:
This is probably an easy one but I'm banging my head against the wall trying to sculpture the perfect Google search. Anyway... Is there a way to determine the current connection's database context? By database context, I mean the current database selected by the last USE or the default database for the user. This may sound dumb (heck, don't you know the last USE statement you issued?) but I'm trying to debug a multi-threaded application...
2
1856
by: plaguna | last post by:
I have MS Access 2007 (My Database files are saved as .mdb extension). I have no problem to create Users and Groups, and grant them specific Permissions. What I don’t understand is why when I create Password, and Permissions to allow or restrict the access of users and Groups to the objects in a specific Database file, (Ex: for only Sales.mdb) it creates security password for all (*.mdb) files. Some DB files don’t need any type of security...
0
8256
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8635
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8356
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7184
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4193
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2621
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1803
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1500
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.