title: I have a table that looks like:
body: <p>I have a table that has </p>
  
  <pre><code>     Material   90    89     88    87    ….2     1     0
        123456    34    30     26    38     14    12     8
        123457    47    42     33    54     38    27    42
  </code></pre>
  
  <p>And I want to convert it to     </p>
  
  <pre><code>     Date        123456     123457              
      Date()-90       34         47
      Date()-89       30         42
      Date()-88       26         33
      Date()-87       38         54
         ….        …………        ………..
      Date()-2        14         38
      Date()-1        12         27
      Date()           8         42
  </code></pre>
  
  <p>I found this, but am trying to figure out how to use it:</p>
  
  <pre><code>Private Sub Unpivot_Click()
      Dim x As Integer
      Dim columncount As Integer
      Dim setRST As DAO.Recordset
      Dim sqlstr As String
      Dim qdf As DAO.QueryDef
      Dim fld As DAO.Field
  
      Set setRST = CurrentDb.OpenRecordset("Select * from TheTable")
  columncount = setRST.Fields.Count
      Set qdf = db.CreateQueryDef ("", "Insert Into TheDestination ([Template], [Row], 
  [Column], [Result]) VALUES (@Template, @RowNumber, @ColumnNumber, @Result)")
  Do While Not setRST.EOF
     qdf.Parameters("@Template") = setRST!Template
     qdf.Parameters("@RowNumber") = setRST!row
     For Each fld In setRST.Fields
         If IsNumeric(fld.Name) Then
              qdf.Parameters("@ColumnNumber") = fld.Name
              qdf.Parameters("@Result") = fld.Value
              qdf.Execute 
         End If
        Next fld
        setRST.MoveNext
     Loop
  
  End Sub
  </code></pre>
  
  <p>So far, I have:</p>
  
  <pre><code>Public Function Unpivot()
  
  Dim x As Integer
  Dim columncount As Integer
  Dim setRST As DAO.Recordset
  Dim sqlstr As String
  Dim qdf As DAO.QueryDef
  Dim fld As DAO.Field
  
  Set setRST = CurrentDb.OpenRecordset("SSMaterialByDayQ322")
  columncount = setRST.Fields.Count
  Set qdf = db.CreateQueryDef("", "Insert INTO SSHistoryQ322 ([Date], [Row], [Column], [Result]) VALUES (@Template, @RowNumber, @ColumnNumber, @Result)")
  Do While Not setRST.EOF
     qdf.Parameters("@Template") = setRST!Date
     qdf.Parameters("@RowNumber") = setRST!row
     For Each fld In setRST.Fields
         If IsNumeric(fld.Name) Then
              qdf.Parameters("@ColumnNumber") = fld.Name
              qdf.Parameters("@Result") = fld.Value
              qdf.Execute
         End If
     Next fld
     setRST.MoveNext
  Loop
  
  End Function
  </code></pre>