Question : Transpose Columns to Rows

I am transposing a table and I had it working, until I added my date fields. . .

Here is my original table (tblcurrentschedule)
WorkOrder_Base_ID   Sequence_No   Resource_ID   9/1/2010   9/2/2010  9/3/2010
wo-12345                   10                    200-415          18                        
wo-12345                   20                    225-395                        18          
wo-12345                   30                    200-415                                        5

Here is what I would like it to look like (tbloperationsched)
WorkOrder_Base_ID   Sequence_No   Resource_ID   Start_Date
wo-12345                   10                    200-415          9/1/2010                        
wo-12345                   20                    225-395          9/2/2010        
wo-12345                   30                    200-415          9/3/2010

My problem comes into play when I transpose the dates into one field called "Start_Date"

TIA,  Here is my code.  My loop is incorrect and the fldField value . .

Public Sub TransposeXtab()
Dim rs As DAO.Recordset, rs1 As DAO.Recordset, rst As DAO.Recordset
'Dim i As Integer, xDate, sql As String
Dim fldField As DAO.Field
Set rs = CurrentDb.OpenRecordset("tblcurrentschedule")     '<<< change to name of table with crosstab data
Set rst = CurrentDb.OpenRecordset("tbloperationsched")     '<<< change to name of table
   
  For i = 3 To rs.Fields.Count - 1
       
       '***  this part use your conversion of week number to date
 
 '      xDate = CDate(Week2Date(rs(i).Start_date, Year(Date)))

       '********
 
        sql = "select * from tblcurrentschedule where reschedule = yes"
        Set rs1 = CurrentDb.OpenRecordset(sql)
        If Not rs1.EOF Then
        rs1.MoveFirst
            Do Until rs1.EOF
              For Each fldField In rs1tblCurrentSchedule.Fields
                 If Field.Value Like "## */*/####" Then 'Date Field
                   With rst
                     .AddNew
                     .Fields("workorder_base_id") = rs1("workorder")
                     .Fields("SEQUENCE_NO") = rs1("SEQUENCE_NO")
                     .Fields("RESOURCE_ID") = rs1("RESOURCE_ID")
                     .Fields("START_DATE") = Mid(fldField.Value, 3)
                     .Update
                   
                   End With
                End If
              Next
              rs1.MoveNext
            Loop
        End If
    Next

rs.Close
rst.Close
rs1.Close
End Sub



Answer : Transpose Columns to Rows

Dont forget it is field name not value you need to check...

Based on the column names being 9/1/2010, have a look at :

Sub UnPivot_Schedule()
    Dim rst As DAO.Recordset
    Dim fld As DAO.Field
   
    Set rst = CurrentDb.OpenRecordset("tblcurrentschedule")
    rst.MoveFirst
   
    Do Until rst.EOF
       For Each fld In rst.Fields
           If fld.Name Like "*/*/####" And fld.Value > 0 Then 'Date Field
              MsgBox rst.Fields("workorder_base_id") & " : " & rst.Fields("Sequence_No") & " : " & fld.Name & " : " & fld.Value
           End If
           Next fld
       rst.MoveNext
       Loop
   
    rst.Close
    Set rst = Nothing
    Set fld = Nothing
End Sub
Random Solutions  
 
programming4us programming4us