Results 1 to 6 of 6

Thread: [RESOLVED] Choose which field to group by - Access

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2006
    Posts
    79

    Resolved [RESOLVED] Choose which field to group by - Access

    Hi. I created a report in Access. I want to give the user a choice which fields she wants the report to be grouped by. Is there a way to do that in Access?

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Choose which field to group by - Access

    Are you creating your report based on an SQL query and just need to add an appropriate ORDER BY clause?

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Dec 2006
    Posts
    79

    Re: Choose which field to group by - Access

    yes, I created it using a query. In the sql I should add an order by saying order by [choose field] - how would that work?

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Choose which field to group by - Access

    Place all of the potential fields in a Multiselect ListBox. Have the users select whatever they want, then store they selections in a string. Put a button on by the Listbox that they need to click when they are done making their decision. Then, just loop through the listbox and there is your ORDER BY clause.
    Code:
    Private Sub cmdDone_Click()
    Dim i As Long
    Dim strOrderBy As String
        For i = 0 To List1.ListCount - 1
            If List1.Selected(i) Then
                strOrderBy = strOrderBy & List1.List(i) & ", "
            End If
        Next
        'this is necessary so that there is no comma after the last selection.
        strOrderBy = Left(strOrderBy, (Len(strOrderBy) - 2))
    MsgBox "ORDER BY " & strOrderBy
    End Sub

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Dec 2006
    Posts
    79

    Re: Choose which field to group by - Access

    I put a list box on the page - and wrote the sub in the button on click event but it's giving me the error that the method 'list' is not a valid method for a list box

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Dec 2006
    Posts
    79

    Re: Choose which field to group by - Access

    I used the ItemData method instead of the list method. Thanks for all your help!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width