Connecting Tech Pros Worldwide Help | Site Map

How can I transpose a table/query in Access?

Newbie
 
Join Date: Apr 2009
Posts: 12
#1: Sep 5 '09
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
best answer - posted by ADezii
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.
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,672
#2: Sep 6 '09

re: How can I transpose a table/query in Access?


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.
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,672
#3: Sep 6 '09

re: How can I transpose a table/query in Access?


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.
ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Posts: 5,213
#4: Sep 6 '09

re: How can I transpose a table/query in Access?


Quote:

Originally Posted by jenniferhelen View Post

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

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.
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,672
#5: Sep 6 '09

re: How can I transpose a table/query in Access?


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 ;)
ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Posts: 5,213
#6: Sep 6 '09

re: How can I transpose a table/query in Access?


Quote:

Originally Posted by NeoPa View Post

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 ;)

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
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,672
#7: Sep 6 '09

re: How can I transpose a table/query in Access?


Quote:

Originally Posted by ADezii View Post

Guess I'm just bored! (LOL)!

I expect Jennifer is thanking her lucky stars at the moment that she caught you at an idle moment :D
Newbie
 
Join Date: Apr 2009
Posts: 12
#8: Sep 13 '09

re: How can I transpose a table/query in Access?


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
ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Posts: 5,213
#9: Sep 14 '09

re: How can I transpose a table/query in Access?


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, 15 views)
Newbie
 
Join Date: Apr 2009
Posts: 12
#10: Sep 20 '09

re: How can I transpose a table/query in Access?


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
ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Posts: 5,213
#11: Sep 20 '09

re: How can I transpose a table/query in Access?


Quote:

Originally Posted by jenniferhelen View Post

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

Not a problem, Jennifer.
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,672
#12: Sep 21 '09

re: How can I transpose a table/query in Access?


Quote:

Originally Posted by jenniferhelen View Post

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.

You're good Jennifer.

I do appreciate how difficult it is to express a question clearly enough to garner the right sort of response.

I'm happy you found ADezii for this anyway.
Reply

Tags
access, crosstab, pseudo row, rows into columns, transpose