Results 1 to 8 of 8
  1. #1
    NISMOJim is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2010
    Posts
    273

    User decides how to sort

    I'm working on a form to enter search parameters to generate a Parts report. My report has fields like Arrival date, Disposal date, Part Number, Description, etc. Users want to be able to sort the report by either Arrival Date, or Disposal Date, depending on what they are working on. I would like to add these options to my form, then the user would click a command button to open the report based on their criteria. My skills are below par, so hopefully something fairly easy is possible. Any suggestions?



    As always, thank you for your guidance!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    Use VBA to construct sort criteria and apply to form OrderBy property.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    NISMOJim is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2010
    Posts
    273
    But the only thing on the parameters form is a combobox to select the name of the part owner, and an option group to sort by either Arrival Date or Disposal Date. The relevant data is displayed in the report. The name filtering (based on the name selected on the parameters form) is done in the underlying query when the report opens, I just can't grasp how to sort by either date field based on the selection. I was thinking something like...If opt1 = 1 then sort by Arrival Date, descending. If opt2 = 2 then sort by Disposal Date, descending. Maybe this would be somewhere on the OnOpen property of the report or an If statement in the sort property of the query? Just not sure how to make it happen.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    Perhaps code in the Option Group frame control Click or AfterUpdate event.

    Me.OrderBy = IIf(Me.grpDate = 1, "[Arrival Date]", "[Disposal Date]") & " DESC"

    Access tends to save the last Filter and OrderBy parameters when the form closes. That's why I set the FilterOnLoad property to No.

    I've never coded for dynamic sorting.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    NISMOJim is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2010
    Posts
    273
    I have to (again) apologize for my ignorance June7, I'm just not getting it. I bounced around the internet for most of today, and came up with this...

    Here is the code on the "Open Report" command button on the parameters form (part owner's name selected as a filter built into the query, and a sorting selection made by the user via an options group to either sort by Arrival Date or Disposal Date)...

    Private Sub cmdReport_Click()
    Dim strDoc As String
    Dim strSOrder As String
    strDoc = "rptDisposition"

    If Me.grpSort = 1 Then
    strSOrder = "OrderBy [DateRecd] DESC"
    ElseIf Me.grpSort = 2 Then
    strSOrder = "OrderBy [DispDate] DESC"
    End If

    DoCmd.OpenReport strDoc, acViewPreview, , , , strSOrder

    End Sub

    Then on the "On Open" event for the report is this...

    Private Sub Report_Open(Cancel As Integer)
    Dim strSOrder As String
    strSOrder = Me.OpenArgs


    End Sub

    I'm not getting any errors, but I'm also not getting any change in the way the report records are sorted. Is the problem in the syntax of the "OrderBy" part, or somewhere (everywhere) else?

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    Don't include OrderBy in the string.

    DoCmd.OpenReport strDoc, acViewPreview, , , , IIf(Me.grpSort = 1, "[Arrival Date]", "[Disposal Date]") & " DESC"

    Then:

    Me.OrderBy = Me.OpenArgs

    Then also need:

    Me.OrderByOn = True

    Won't work on report set up with Grouping & Sorting.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    NISMOJim is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2010
    Posts
    273
    That did the trick! Thank you again for your help. People like you make people here think I know what I'm doing.

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    Might find this of interest http://allenbrowne.com/ser-33.html
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 9
    Last Post: 04-08-2014, 10:39 AM
  2. Replies: 1
    Last Post: 04-07-2014, 02:59 AM
  3. sort filter, doesn't sort everything
    By deso in forum Queries
    Replies: 4
    Last Post: 01-25-2013, 05:27 AM
  4. Replies: 1
    Last Post: 07-20-2012, 05:35 PM
  5. How to sort by three sort orders
    By captgnvr in forum Access
    Replies: 4
    Last Post: 11-09-2009, 07:30 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