Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorting report by category in form Combobox?

Status
Not open for further replies.

CTOROCK

Programmer
May 14, 2002
289
US

How can I sort a report by a category selected in a combobox? Something like this

Dim StrSort
StrSort = CmbSort.Value

DoCmd.OpenReport Rpt_Sort, acPreview,, Sortby Strsort ascending

Thanks in advance

"The greatest risk, is not taking one."
 
Looks like you are looking for a WHERE statement, vs. "SORT"? You are opening the report to see one single "category", right? No need to sort by it if there is only one.

Also, you need quotes around the report name, and after the third comma is the WHERE statement (not a sort statement):

DoCmd.OpenReport "Rpt_Sort", acPreview,,"CategoryFieldName = '" & me.CmbSort "'"

(substitute in the name of the category field in your report's recordsource for "CategoryFieldName") This is using single quotes, assuming "Category" is text (since you dim'd it as 'str' earlier).

If you really want to sort something, do it in the report's recordsource or in the SORTING AND GROUPING feature of the report itself.


Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244. Basics at
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top