I have a report template in Word that pulls tables from an Access 2007 database. The tables should be exactly structured as they should appear in the report since we want to do a minimal amount of post-processing a formatting after up开发者_StackOverflowdating the fields in the template.
In one step I use some VBA and a DAO.RecordSet to add a TOTAL row to the bottom of the table. The last bit there under "Add the total row" is where the row is added.
I want this row to be the LAST row in the table so when we update the fields in the Word report we don't have to move it around. About 90% of the time it works all the time :) but occasionally it will put the Total row at the top. I'm not sure how to force it to the bottom of the table. Any hints or workarounds?
I've found a SQL statement is even worse, it almost always adds the total row to the top.
Thanks!
'Add the total row.
rs1.MoveLast
rs1.AddNew
rs1.Fields(fname) = "Total"
rs1.Fields("Frequency") = TotalSum
rs1.Fields("Percent") = "100.0%"
rs1.Update
rs1.Close
In a relational database, there is no such thing as first or last, only an order that you impose with a field on which to sort. This is often an ID or date. Add a suitable field and then sort by that field when extracting the data. When adding a record, make sure it fits in the sequence you want by updating the sort field.
精彩评论