473,654 Members | 3,108 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can I transpose a table/query in Access?

15 New Member
I am working with a query that has 6 columns and 101 rows; I would like to transpose the rows and columns. I have tried using a crosstab query but Access limits the row "fields" to 3 and this was not producing the desired output. I saw a comment in a thread about using a pseudo row field as a work around but I do not understand how this works.
Another option I tried is from the following link and attempting method 2: http://support.microsoft.com/kb/202176. I must say I am not a programmer and only have a vague idea of what is going on in the code. However I gave it a shot and entered my query information into the Immediate window. When I selected enter I received an immediate error "3027 record is too large", however a table was created with 101 columns correctly but only 3 of the 6 rows were created and none of the numeric data was populated relating to the rows and columns. At this point I am lost and frustrated and would greatly appreciate any advice you can offer.
Jennifer
Sep 5 '09 #1
12 19835
NeoPa
32,568 Recognized Expert Moderator MVP
Having followed the link myself, it seems to provide a decent solution for your problem. I'm not sure what you want from us.

I know the concept is not the most straightforward , but if you can't understand it I fail to see how we can help. If there's a specific point you get stuck on ask away, but we can't do your work for you.

We wouldn't even if we did know enough about your particular problem, but we don't anyway, of course.
Sep 6 '09 #2
NeoPa
32,568 Recognized Expert Moderator MVP
I've just found your other posted question, which I've replied to. If Excel is an option for you then it is much simpler. Excel does it all for you. Such a facility is not available in Access, even if something can be designed to do the work for you.
Sep 6 '09 #3
ADezii
8,834 Recognized Expert Expert
@jenniferhelen
I agree with NeoPa in that the posted Link is indeed a decent solution. I am revising the code to eliminate the Target Argument. The New Target Name will be the Source Name plus _Transposed. If the Target already exists, it will be Deleted. You will only need to supply a Source Name. If you do not wish to manually supply a Source Name, that can even be eliminated but one step at a time. I will also include all this functionality in a Demo Database for you, so you can get a better picture of everything. Be patient - will see you soon.
Sep 6 '09 #4
NeoPa
32,568 Recognized Expert Moderator MVP
ADezii,

Bear in mind there is a parallel thread (How do you successfully transpose rows into columns in Excel?) posted by Jennifer which looks at an alternative approach that doesn't need this to be done within Access as such.

There's no reason you shouldn't go ahead if it's something that grabs you, but just so as you know ;)
Sep 6 '09 #5
ADezii
8,834 Recognized Expert Expert
@NeoPa
Thanks NeoPa, and I am aware of what you have stated. I've developed an Algorithm which should theoretically eliminate all Column restrictions as previously indicated by the OP. This Algorithm does not create a Table or Fields, and is not hampered by Access Table limitations. Access does the Transposing internally, and then outputs the Data to a Comma Delimited File in the same Directory as the Database and named Source & _Transposed.txt . This File can now be easily Imported into a variety of External Applications. It has not been refined at this point but I'll post it anyway in case anyone is interested. Guess I'm just bored! (LOL)!
Expand|Select|Wrap|Line Numbers
  1. Function fTranspose(strSource As String)
  2. Dim MyDB As DAO.Database
  3. Dim rstSource As DAO.Recordset
  4. Dim i As Integer
  5. Dim strBuild As String
  6. On Error GoTo fTranspose_Err
  7.  
  8. Set MyDB = CurrentDb()
  9. Set rstSource = MyDB.OpenRecordset(strSource)
  10. rstSource.MoveLast: rstSource.MoveFirst
  11.  
  12. Open CurrentProject.Path & "\" & strSource & "_Transposed.txt" For Output As #1
  13.  
  14. 'The Transposing is done within this Nested Structure
  15. With rstSource
  16.   For i = 0 To .Fields.Count - 1
  17.     Do While Not .EOF
  18.       strBuild = strBuild & .Fields(i).Value & ", "
  19.       .MoveNext
  20.     Loop
  21.       .MoveFirst
  22.        Debug.Print .Fields(i).Name & ", " & Left$(strBuild, Len(strBuild) - 2)
  23.          Print #1, .Fields(i).Name & ", " & Left$(strBuild, Len(strBuild) - 2)
  24.            strBuild = ""       'reset
  25.   Next i
  26. End With
  27.  
  28. Close #1
  29.  
  30. rstSource.Close
  31. Set rstSource = Nothing
  32.  
  33. Exit_fTranspose:
  34.   Exit Function
  35.  
  36. fTranspose_Err:
  37.   Select Case Err
  38.     Case 3078
  39.       MsgBox "The Object " & strSource & " doesn't exist."
  40.     Case Else
  41.       MsgBox Err.Description, vbExclamation, "Error in fTranspose()"
  42.   End Select
  43.     Resume Exit_fTranspose:
  44. End Function
Sep 6 '09 #6
NeoPa
32,568 Recognized Expert Moderator MVP
@ADezii
I expect Jennifer is thanking her lucky stars at the moment that she caught you at an idle moment :D
Sep 6 '09 #7
jenniferhelen
15 New Member
ADezii,
I am extremely grateful for all the time you spent on my problem. I have spent much time trying to use it but I am very inexperienced in this area. Whenever I try to run the code, I am prompted with a macro box. I do not have any macros in this database so I am not sure what is expected at this point. I entered an "a" at this prompt and then selected the Create button (the only other option was the Cancel button). The result was the following text was added after your code, "sub a() end sub".
Again I really appreciate all you have done.

NeoPa,
I appreciate your comments as well and I never meant to imply I wanted anything done for me. I apologize if I offended you.

Regards,
Jennifer
Sep 13 '09 #8
ADezii
8,834 Recognized Expert Expert
Jennifer, download the Demo (Attachment) that I have now made available to you. With it you can Transpose any 1 of 3 Tables to a TAB Delimited/Quotes surrounding Strings, Text File. This File can then be easily Imported into Excel.
Attached Files
File Type: zip Transpose.zip (34.7 KB, 1021 views)
Sep 13 '09 #9
jenniferhelen
15 New Member
ADezii,
Thanks again for the code and example database. It works perfectly and beautifully in the example. I am in the process of implementing it in my database. I really appreciate all your help.
Take care,
Jennifer
Sep 20 '09 #10

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

Similar topics

1
3068
by: PMB | last post by:
Thank you in advance for any and all assistance. I'm trying to use a make table query to pull the last transactionID, so I can use an append query to reset the transactionID to the next sequential number. My problem is, the make table query is taking all the TransactionID's and putting them in the new table. Is there a way to take the last transactionID only and put it in the new table? So this way, when I clear the old Transactions,...
4
2387
by: Oreo Bomb | last post by:
I have a secured database that contains a Read-Only group. This group has permissions to view reports, but cannot add, edit, or delete any DB objects. One of the reports the group needs access to is generated with a Make-Table Query. Since the Make-Table Query deletes the previous table it created everytime it's ran, this poses a problem since the Read-Only group doesn't have the permission to delete objects. This causes the report...
4
2854
by: Alan Lane | last post by:
Hello world: I'm including both code and examples of query output. I appologize if that makes this message longer than it should be. Anyway, I need to change the query below into a pivot table query. I'm having trouble doing it. Help! Here is my code so far: Sub OldRegionQuery()
3
2360
by: tdmailbox | last post by:
I set up my code to disable the shift bypass however for certain users I want to allow them through a button no a form to be able open up the list of tablies and queries. Is there a vb command to open up the user interface that lets you view the list of tables and queries that you would see if you did a shift bypass?
2
2093
by: Doc | last post by:
Per earlier post, I am trying to save 'out' production data from a program called Solomon - basically (I think) this was /is an Access/Sql based program. We are updating to different application and I need to bring over ONLY certain DATA. When I did an ODBC link to the DB all the tables are present. I linked the three or four tables and have my fields (these are the ones I want to modify for LATER import into the new application)
1
2537
by: danijela.simunovic | last post by:
Hi! Is there a way that when I run a "make table query" and an "append query" that i won't be asked those 2 or 3 questions from access like :"you are about to run a make table...","the existing table ABCDE will be deleated..." and so on prompting for yes or no! I would like to make a command button which would prompt me for yes or no and then if i say "yes" it would first run the make table query and then the append query without...
4
12333
by: ken | last post by:
Hi, I use this command to run a make table query without opening it... CurrentDb.Execute "make table query name" Access tells me that it can't execute a select query...? Its a make table query not a select? Or are those two the same. Bottom line is that the DoCmd.OpenQuery alowes the user to see the query and I don't want that... Anything else I could use other then Currentdb.execute?
6
1677
by: BrianDP | last post by:
I have a table that has always been in my back-end of this application. The table is getting quite large, and, on top of that, we lose records out of this table. They just dissappear! No rhyme or reason to it. I imported the table into SQL, and re-linked it back into the front end of the application. All the fields show. I had to pick a primary key, which is fine, it's a text field (nvarchar 255), and it is indeed a unique value. ...
3
3465
by: Robertf987 | last post by:
Hi, I'm a bit stuck with an access database. I'm using access 2000 if that's any help. Right, it's 3:40am right now and I'm rather tired, but I *hope* this makes sense. I have a table which contains the main data of the database, records of information of grants. For each financial year, the old data needs taking out of the table. Basically I have two options: delete the old data from the year before, or back it up in a new table. I'd rather...
9
18743
by: Mourad | last post by:
Hi All, Is it possible to create a Make Table query in access (2.0 and 2003) that creates the table into a SQL Server database? Following the steps: 1- Create New Query 2- Set Query Type as Make-Table query 3- Enter table name 4- Click "Another Database", click Browse, then I cannot see anything
0
8372
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
8285
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8706
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
8475
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
8591
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7304
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...
1
6160
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4293
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2709
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

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.