Results 1 to 4 of 4
  1. #1
    MFS is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2009
    Location
    Ohio
    Posts
    235

    Help with sorting a form

    Hello,
    I have been working on a database that Rawb had helped me build, I had a question that I'm hoping someone or quite possibly Rawb may be able to help me with.


    On my "Employee Timesheet" form; is there a way to sort the employees alphabetically? (So when the form opens the employees are alphabetically in order)
    Also, I added a "shift" field to this form, is there a way to have it show all the "A" shift 1st then the "B" shift and then "C"? (Sorted from A to C)
    Attached is a copy of my DB,
    Thank You in advance,

    Speck
    Attached Files Attached Files

  2. #2
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    I can't open a 2010 file, but assuming you have a first name and last name, as you should, in the Form_Load event:

    Code:
    Me.OrderBy = "[ShiftField] ASC, [LastName] ASC, [FirstName] ASC"
    Me.OrderByOn = True


    Change the Field names to the actual names, of course.

    Linq ;0)>

  3. #3
    Rawb is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Dec 2009
    Location
    Somewhere
    Posts
    875
    On the Employee Timesheet Form, there's a VBA Sub called Form_Requery(). You will need to update the SQL Query in that Sub with the sorting you want:
    Code:
    Private Sub Form_Requery()
      Me.Form.RecordSource = "SELECT Timesheet.* FROM Timesheet INNER JOIN Employees ON Employees.[Employee_ID] = Timesheet.[Employee_ID] WHERE Timesheet.[Coordinator_ID]=" & Nz(Me!cboCoordinator.Column(0), "0") & " AND Timesheet.[Period_End]=#" & Nz(Me!cboPeriodEnding, CDate(0)) & "# ORDER BY Timesheet.[Shift_ID], Employees.[Name_Last], Employees.[Name_First]"
      Me.Form.Requery
    End Sub
    In the above code, I changed the sorting from the "default" of Employee_ID (which I should never have done in the first place!) to sorting by the Shift, then last name, then first name.

    Also, it might be worth it to include the employee's name in the Timesheet Table directly. That way, if someone changes their name (gets married/divorced, for example) it will properly show their name at that time. You would still be able to find out their current name by searching the Employees Table.

  4. #4
    MFS is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2009
    Location
    Ohio
    Posts
    235
    Rawb, This is perfect, Thank You so very much. This little DB is going to help the Coordinators within my company tremendously.

    Missinglinq Thank You as well for your help.

    Speck

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

Similar Threads

  1. Sorting on a form
    By Ayiramala in forum Access
    Replies: 5
    Last Post: 01-25-2015, 10:32 PM
  2. Sorting a report using combo box on a form.
    By sanjayakalpage in forum Reports
    Replies: 1
    Last Post: 01-21-2015, 11:44 PM
  3. Replies: 11
    Last Post: 01-12-2012, 07:55 PM
  4. Sorting a filtered form
    By mikeal_a@yahoo.com in forum Forms
    Replies: 1
    Last Post: 07-26-2011, 08:30 AM
  5. Sorting in a form
    By PaulDouglas in forum Forms
    Replies: 3
    Last Post: 07-27-2006, 08:28 AM

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