|
-
Mar 7th, 2007, 08:33 AM
#1
Thread Starter
Lively Member
[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?
-
Mar 7th, 2007, 09:01 AM
#2
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?
-
Mar 7th, 2007, 09:04 AM
#3
Thread Starter
Lively Member
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?
-
Mar 7th, 2007, 10:19 AM
#4
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
-
Mar 21st, 2007, 12:05 PM
#5
Thread Starter
Lively Member
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
-
Mar 21st, 2007, 12:29 PM
#6
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|