473,405 Members | 2,272 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Transposing Data Tables...Need Help!

I have a sanitized database which I have attached, and for the most part transposes the data to my liking. There is however a few issues that I would like to fix, but cannot determine the problem in my code. Basically, the text field AccountNumber is being recognized as data, along with the account numbers and classes being populated incorrectly. If you run the attachment you will see my error. I appreciate anyones help in this matter. Thank you.

Expand|Select|Wrap|Line Numbers
  1. Function test()
  2. Dim i As Integer, x As Integer
  3.   Dim rs As Recordset, rs2 As Recordset
  4.     Set rs = CurrentDb.OpenRecordset("table1", dbOpenDynaset)
  5.       Set rs2 = CurrentDb.OpenRecordset("newtable", dbOpenDynaset)
  6. With rs
  7.     .MoveLast
  8.     .MoveFirst
  9.   End With
  10. With rs2
  11.  
  12.     x = 1
  13.  
  14.         Do Until rs.EOF
  15.  
  16.           Do Until x = rs.Fields.Count
  17.             .AddNew
  18.  
  19.               !Date = rs.Fields(0)
  20.               !AccountNumber = rs.Fields(x).Name
  21.               !ClassNumber = rs.Fields(x)
  22.               !Percent = rs.Fields(x)
  23.             .Update
  24.     x = x + 1
  25.           Loop
  26.       x = 1
  27.             rs.MoveNext
  28.         Loop
  29.     rs.Close
  30.   .Close
  31. End With
  32. Set rs = Nothing
  33.   Set rs2 = Nothing
  34. End Function
  35.  
Attached Files
File Type: zip Transpose.zip (62.3 KB, 93 views)
Mar 27 '08 #1
10 1550
ADezii
8,834 Expert 8TB
I have a sanitized database which I have attached, and for the most part transposes the data to my liking. There is however a few issues that I would like to fix, but cannot determine the problem in my code. Basically, the text field AccountNumber is being recognized as data, along with the account numbers and classes being populated incorrectly. If you run the attachment you will see my error. I appreciate anyones help in this matter. Thank you.

Expand|Select|Wrap|Line Numbers
  1. Function test()
  2. Dim i As Integer, x As Integer
  3.   Dim rs As Recordset, rs2 As Recordset
  4.     Set rs = CurrentDb.OpenRecordset("table1", dbOpenDynaset)
  5.       Set rs2 = CurrentDb.OpenRecordset("newtable", dbOpenDynaset)
  6. With rs
  7.     .MoveLast
  8.     .MoveFirst
  9.   End With
  10. With rs2
  11.  
  12.     x = 1
  13.  
  14.         Do Until rs.EOF
  15.  
  16.           Do Until x = rs.Fields.Count
  17.             .AddNew
  18.  
  19.               !Date = rs.Fields(0)
  20.               !AccountNumber = rs.Fields(x).Name
  21.               !ClassNumber = rs.Fields(x)
  22.               !Percent = rs.Fields(x)
  23.             .Update
  24.     x = x + 1
  25.           Loop
  26.       x = 1
  27.             rs.MoveNext
  28.         Loop
  29.     rs.Close
  30.   .Close
  31. End With
  32. Set rs = Nothing
  33.   Set rs2 = Nothing
  34. End Function
  35.  
Just subscribing, will return later.
Mar 27 '08 #2
ADezii
8,834 Expert 8TB
I have a sanitized database which I have attached, and for the most part transposes the data to my liking. There is however a few issues that I would like to fix, but cannot determine the problem in my code. Basically, the text field AccountNumber is being recognized as data, along with the account numbers and classes being populated incorrectly. If you run the attachment you will see my error. I appreciate anyones help in this matter. Thank you.

Expand|Select|Wrap|Line Numbers
  1. Function test()
  2. Dim i As Integer, x As Integer
  3.   Dim rs As Recordset, rs2 As Recordset
  4.     Set rs = CurrentDb.OpenRecordset("table1", dbOpenDynaset)
  5.       Set rs2 = CurrentDb.OpenRecordset("newtable", dbOpenDynaset)
  6. With rs
  7.     .MoveLast
  8.     .MoveFirst
  9.   End With
  10. With rs2
  11.  
  12.     x = 1
  13.  
  14.         Do Until rs.EOF
  15.  
  16.           Do Until x = rs.Fields.Count
  17.             .AddNew
  18.  
  19.               !Date = rs.Fields(0)
  20.               !AccountNumber = rs.Fields(x).Name
  21.               !ClassNumber = rs.Fields(x)
  22.               !Percent = rs.Fields(x)
  23.             .Update
  24.     x = x + 1
  25.           Loop
  26.       x = 1
  27.             rs.MoveNext
  28.         Loop
  29.     rs.Close
  30.   .Close
  31. End With
  32. Set rs = Nothing
  33.   Set rs2 = Nothing
  34. End Function
  35.  
Sorry eskelies, but you are going to have to fill me in as far as Field Alignments go:
Expand|Select|Wrap|Line Numbers
  1. Table1.Date ==> newtable.Date
  2. Table1.AccountNumber ==> newtable.AccountNumber
Expand|Select|Wrap|Line Numbers
  1. Table1.1 ==> newtable.?
  2. Table1.2 ==> newtable.?
  3. Table1.3 ==> newtable.?
  4. Table1.7 ==> newtable.?
  5. Table1.8 ==> newtable.?
  6. Table1.9 ==> newtable.?
How does newtable.ClassNumber and newtable.Percent fit into the overall picture?
Mar 27 '08 #3
AD,

I hope I understand your question. Each fund number should have multiple classes (ie. 1,2,3,7,8,9) to be exact. Each Class will have a percent associated with that. As far as field date is concerned I am going to ultimately have two tables. One for current date and the other prior date. I will need these dates because I will be building queries off these.

Hope this helps!
Mar 27 '08 #4
ADezii
8,834 Expert 8TB
AD,

I hope I understand your question. Each fund number should have multiple classes (ie. 1,2,3,7,8,9) to be exact. Each Class will have a percent associated with that. As far as field date is concerned I am going to ultimately have two tables. One for current date and the other prior date. I will need these dates because I will be building queries off these.

Hope this helps!
For the sake of absolute clarity, kindly post the Field data from a single Record in Table1, then a display of how the Transposed data will appear in newtable along with the Field assignments. I understand that a given Account Number has 6 Classes (1, 2, 3, 7, 8, and 9) associated with it but how is the Percent Field derived from the values in Table1, then transposed to newtable?
Mar 27 '08 #5
For the sake of absolute clarity, kindly post the Field data from a single Record in Table1, then a display of how the Transposed data will appear in newtable along with the Field assignments. I understand that a given Account Number has 6 Classes (1, 2, 3, 7, 8, and 9) associated with it but how is the Percent Field derived from the values in Table1, then transposed to newtable?
Table1:

Date AccountNum 1 2 3 7 8 9

12/31/9999 20 3% 3.01% 3% 3.17% 3.12%


New Table:

Date AccountNum Class Num Percent


12/31/9999 20 1 3%

12/31/9999 20 2 3.01%

12/31/9999 20 3 3%

12/31/9999 20 7

12/31/9999 20 8 3.17%

12/31/9999 20 9 3.12%


Note: If Class has null value leave null.
Mar 28 '08 #6
ADezii
8,834 Expert 8TB
Table1:

Date AccountNum 1 2 3 7 8 9

12/31/9999 20 3% 3.01% 3% 3.17% 3.12%


New Table:

Date AccountNum Class Num Percent


12/31/9999 20 1 3%

12/31/9999 20 2 3.01%

12/31/9999 20 3 3%

12/31/9999 20 7

12/31/9999 20 8 3.17%

12/31/9999 20 9 3.12%


Note: If Class has null value leave null.
Gotcha, I'll try and have the code for you tomorrow.
Mar 28 '08 #7
Thanks man I appreciate it!
Mar 28 '08 #8
ADezii
8,834 Expert 8TB
Thanks man I appreciate it!
Actually, once I got an exact picture of what had to be done, it was fairly simple. Replace all your Function code (Test()) with the following:
Expand|Select|Wrap|Line Numbers
  1. Dim MyDB As DAO.Database
  2. Dim rs As DAO.Recordset
  3. Dim rs2 As DAO.Recordset
  4. Dim intCounter As Integer
  5.  
  6. Set rs = CurrentDb.OpenRecordset("table1", dbOpenSnapshot)
  7. Set rs2 = CurrentDb.OpenRecordset("newtable", dbOpenDynaset)
  8.  
  9. Do While Not rs.EOF
  10.   With rs2
  11.     For intCounter = 2 To 7
  12.       .AddNew
  13.         !Date = rs.Fields(0)
  14.         ![AccountNUmber] = rs.Fields(1)
  15.         ![ClassNumber] = rs.Fields(intCounter).Name
  16.         ![Percent] = rs.Fields(intCounter)
  17.       .Update
  18.     Next
  19.   End With
  20.   rs.MoveNext
  21. Loop
  22.  
  23. rs.Close
  24. rs2.Close
  25. Set rs = Nothing
  26. Set rs2 = Nothing
Mar 28 '08 #9
AD,

The code works great!

Again I thank you!
Mar 28 '08 #10
ADezii
8,834 Expert 8TB
AD,

The code works great!

Again I thank you!
You are quite welcome. What some Members do no realize is that, at least for me, it is sometimes very difficult to solve problems from the other end of a Web Page. Once you posted the data both from before, and after, the Transposition, the solution was quite clear.
Mar 28 '08 #11

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

Similar topics

2
by: Fabio | last post by:
Hello, is there any quite easy solution for the problem of transposing the rows into the columns? I have the following table with some data in it: dealer date 09.00 10.00 11.00 ...
8
by: Leszek Gruszka | last post by:
Hello! I need to transpose some columns into rows and rows into columns. I know, tha i can do it by cursor, but i don't know how make it... I read a lot about it, but still don't understand......
2
by: Howard William | last post by:
Help. I am a bit flummoxed by the problem of how to transpose "normalized" (in the database sense) data records into columns of for a data entry form, and then back again when the user is...
9
by: Classic-Car-World Ltd | last post by:
Hi, I have some data in a table in columns which I need to convert into rows. This is specification data for some tools etc. The data is currently in the following format: Product No, order,...
1
by: Caspian | last post by:
Dear All, I'm attempting to create a query that will transpose repeated fields into a single table structure. Can anyone think of how this can be done as I'm stumped at the minute? I'd like to...
4
by: m.wanstall | last post by:
Hi there, I have a large table based around a CustomerNumber with various details about that customer (originally imported and augmented from an Exchange Server)...now, a single customer can...
3
by: newb | last post by:
Hey guys, I’m new to access and databases and I’m having a bit of trouble coming up with a query that will do what I need. I have three tables in the form of: Table 1: Category ID, Category ...
11
by: Haydee Zimmerman | last post by:
Hoping someone can help me. I have 2 Access tables with a one to many relationship. the 1 side table holds the billing information, the many table side holds the billing id and modifier#. Now I...
7
by: ekariuki | last post by:
Hi Guys, I am a newbee to Bytes currently working on an MS Access database for one of my clients: With respect, I'll get right to it: I have 2 tables: Table 1. TblTrip_Facts Route Name , ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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...
0
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...
0
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...

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.