I need to convert the code below so that I can sort by "Last Name" when it creates the worksheets.
When I first started this project I didn't think about sorting the summary worksheet, and now the code is all over it so can't sort the names like i need to.
What i need to do is sort by the names in an excel table that come from the individual worksheets, this list of names will have times in the corresponding rows, then I am adding to that a list of names without times, and i'd like to then sort on that but leave the mames with times sorted at the top.
If I can pre sort the recordset it will fix that half of the problem, I can then duplicate that when I add the names without times. When it's all done the sheet will be protected so it can't change.
Code:
Set db = CurrentDb()
Set rs = db.OpenRecordset("create excel time sheets for selected employees on main menu")
With rs
.MoveFirst
Do While Not .EOF
fn = rs.Fields("First Name")
Ln = rs.Fields("Last Name")
cd = rs.Fields("Code #")
bc = rs.Fields("barcode")
Me.barcode = bc
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "print time sheets for selected employees", gg, True, fn & " " & Ln & " " & cd
DoEvents
.MoveNext
Loop
End With