Help | Site Map
Connecting Tech Pros Worldwide
Reply
 
LinkBack Thread Tools
  #1  
Old March 27th, 2008, 03:29 PM
Member
 
Join Date: May 2007
Posts: 55
Default 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, 13 views)
Reply
  #2  
Old March 27th, 2008, 05:03 PM
ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Age: 59
Posts: 4,253
Default

Quote:
Originally Posted by eskelies
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.
Reply
  #3  
Old March 27th, 2008, 06:20 PM
ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Age: 59
Posts: 4,253
Default

Quote:
Originally Posted by eskelies
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?
Reply
  #4  
Old March 27th, 2008, 07:24 PM
Member
 
Join Date: May 2007
Posts: 55
Default

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!
Reply
  #5  
Old March 28th, 2008, 12:34 AM
ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Age: 59
Posts: 4,253
Default

Quote:
Originally Posted by eskelies
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?
Reply
  #6  
Old March 28th, 2008, 01:02 AM
Member
 
Join Date: May 2007
Posts: 55
Default

Quote:
Originally Posted by ADezii
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.
Reply
  #7  
Old March 28th, 2008, 01:32 AM
ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Age: 59
Posts: 4,253
Default

Quote:
Originally Posted by eskelies
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.
Reply
  #8  
Old March 28th, 2008, 02:12 AM
Member
 
Join Date: May 2007
Posts: 55
Default

Thanks man I appreciate it!
Reply
  #9  
Old March 28th, 2008, 03:11 AM
ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Age: 59
Posts: 4,253
Default

Quote:
Originally Posted by eskelies
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
Reply
  #10  
Old March 28th, 2008, 01:37 PM
Member
 
Join Date: May 2007
Posts: 55
Default

AD,

The code works great!

Again I thank you!
Reply
  #11  
Old March 28th, 2008, 04:58 PM
ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Age: 59
Posts: 4,253
Default

Quote:
Originally Posted by eskelies
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.
Reply
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles