G
Guest
I have some code that creates a recordset using SQL including an Order By
Clause
and then writes the data from that recordset to a table. The whole purpose
of this code is to create a table that is sorted the specific way I want. I
could do this using a query but I am trying to do everything in this DB
without using any queries.
When I run the procedure it runs fine but theresulting table is not sorted.
I have tried the Order By clause as well as the sort property and neither
seems to make a difference. I'm sure it's something simple that I've missed
but I can't see it.
Here's the code:
Public Sub FillReportTable()
Dim Db As DAO.Database
Dim rst1 As DAO.Recordset
Dim tdf As TableDef
Dim rst2 As Recordset
Set Db = CurrentDb()
Set rst1 = Db.OpenRecordset("Select * From Comparisons ORDER BY [Project],
[SeqNum];")
Set tdf = Db.TableDefs("Report")
Set rst2 = tdf.OpenRecordset(dbOpenDynaset)
With rst1
If .RecordCount = 0 Then
MsgBox "There's a serious problem"
Exit Sub
End If
.MoveFirst
With rst2
Do While Not rst1.EOF
rst2.AddNew
rst2![Project] = rst1![Project]
rst2![Project Manager] = rst1![Project Manager]
rst2![Actual Labor Units] = rst1![Actual Labor Units]
rst2![Planned Labor Units] = rst1![Planned Labor Units]
rst2![At Completion Labor Units] = rst1![At Completion Labor Units]
rst2![Actual Duration] = rst1![Actual Duration]
rst2![Planned Duration] = rst1![Planned Duration]
rst2![At Completion Duration] = rst1![At Completion Duration]
rst2![Budget Consumed] = rst1![Budget Consumed]
rst2![Effort % Complete] = rst1![Effort % Complete]
rst2![Remaining Effort] = rst1![Remaining Effort]
rst2![Remaining Duration] = rst1![Remaining Duration]
rst2![Committed Elevation Date] = rst1![Committed Elevation Date]
rst2![DataDate] = rst1![DataDate]
rst2![SeqNum] = rst1![SeqNum]
rst2![Duration % Complete] = rst1![Duration % Complete]
rst2![Progress Alert] = rst1![Progress Alert]
rst2![Daily Effort Required] = rst1![Daily Effort Required]
rst2![Average Actual Daily Effort] = rst1![Average Actual Daily Effort]
rst2![Schedule Alert] = rst1![Schedule Alert]
rst2![Duration Variance] = rst1![Duration Variance]
rst2![Effort Variance] = rst1![Effort Variance]
rst2.Update
rst1.MoveNext
Loop
End With
End With
End Sub
TIA,
Clause
and then writes the data from that recordset to a table. The whole purpose
of this code is to create a table that is sorted the specific way I want. I
could do this using a query but I am trying to do everything in this DB
without using any queries.
When I run the procedure it runs fine but theresulting table is not sorted.
I have tried the Order By clause as well as the sort property and neither
seems to make a difference. I'm sure it's something simple that I've missed
but I can't see it.
Here's the code:
Public Sub FillReportTable()
Dim Db As DAO.Database
Dim rst1 As DAO.Recordset
Dim tdf As TableDef
Dim rst2 As Recordset
Set Db = CurrentDb()
Set rst1 = Db.OpenRecordset("Select * From Comparisons ORDER BY [Project],
[SeqNum];")
Set tdf = Db.TableDefs("Report")
Set rst2 = tdf.OpenRecordset(dbOpenDynaset)
With rst1
If .RecordCount = 0 Then
MsgBox "There's a serious problem"
Exit Sub
End If
.MoveFirst
With rst2
Do While Not rst1.EOF
rst2.AddNew
rst2![Project] = rst1![Project]
rst2![Project Manager] = rst1![Project Manager]
rst2![Actual Labor Units] = rst1![Actual Labor Units]
rst2![Planned Labor Units] = rst1![Planned Labor Units]
rst2![At Completion Labor Units] = rst1![At Completion Labor Units]
rst2![Actual Duration] = rst1![Actual Duration]
rst2![Planned Duration] = rst1![Planned Duration]
rst2![At Completion Duration] = rst1![At Completion Duration]
rst2![Budget Consumed] = rst1![Budget Consumed]
rst2![Effort % Complete] = rst1![Effort % Complete]
rst2![Remaining Effort] = rst1![Remaining Effort]
rst2![Remaining Duration] = rst1![Remaining Duration]
rst2![Committed Elevation Date] = rst1![Committed Elevation Date]
rst2![DataDate] = rst1![DataDate]
rst2![SeqNum] = rst1![SeqNum]
rst2![Duration % Complete] = rst1![Duration % Complete]
rst2![Progress Alert] = rst1![Progress Alert]
rst2![Daily Effort Required] = rst1![Daily Effort Required]
rst2![Average Actual Daily Effort] = rst1![Average Actual Daily Effort]
rst2![Schedule Alert] = rst1![Schedule Alert]
rst2![Duration Variance] = rst1![Duration Variance]
rst2![Effort Variance] = rst1![Effort Variance]
rst2.Update
rst1.MoveNext
Loop
End With
End With
End Sub
TIA,