Results 1 to 2 of 2
  1. #1
    trevor40's Avatar
    trevor40 is offline Advanced db Manager
    Windows XP Access 2003
    Join Date
    Feb 2014
    Location
    Australia
    Posts
    402

    convert OpenRecordset("queryname") to sql so i can sort the recordset

    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
    

  2. #2
    trevor40's Avatar
    trevor40 is offline Advanced db Manager
    Windows XP Access 2003
    Join Date
    Feb 2014
    Location
    Australia
    Posts
    402
    again overthinking it, i just sorted the queries then opened then and that fixes it all.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 26
    Last Post: 07-31-2014, 11:04 AM
  2. Replies: 6
    Last Post: 01-29-2014, 08:03 AM
  3. Replies: 4
    Last Post: 01-11-2014, 11:57 PM
  4. Replies: 1
    Last Post: 12-28-2012, 02:54 PM
  5. File Export "sort" issues
    By jgelpi16 in forum Programming
    Replies: 24
    Last Post: 09-15-2010, 12:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums