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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorting Using VB

Status
Not open for further replies.
Jul 5, 2001
40
US
I know that you can right click on a report and choose sorting and grouping, but is there a way to do this using VB. I have several reports which print the exact same information but I have 3 duplicates of each of them just because I don't know a way around this. Can someone please help?
 
darkstar:

Check out the Orderby property in Help. Under Reports, sorting records, OrderBy property.

I think this may be what you are looking for.

You would probably have to call the report three times, changing the sort order between calls.

Hope this helps. Larry De Laruelle
ldelaruelle@familychildrenscenter.org

 
Works great. Just as a tip however to everyone out there. If you set this up after already having the report make sure to remove your current group and sorting information (the stuff by right clicking and selecting grouping an sorting). It makes this process actually work.

Thanks a ton!
 
I use this method quite a bit in this situation. You can create three queries for your three different sort orders for the report(Report1). They would be identical but the Group By or sorting portion of the SQL would be different. For demonstration purposes let's call them qryCaseIDSort, qryNameSort, and qryZipCodeSort. Then using one report(Report1) change the Record Source property to whichever sort order that you want the report printing in. This would be the code behind a button to perform this process:

Dim db As Database
Set db = CurrentDb
Reports!Report1.RecordSource = "qryCaseID#Sort"
DoCmd.OpenReport "Report1", acViewPreview
Reports!Report1.RecordSource = "qryNameSort"
DoCmd.OpenReport "Report1", acViewPreview
Reports!Report1.RecordSource = "qryZipCodeSort"
DoCmd.OpenReport "Report1", acViewPreview
db.Close

This way you are using one report to display it three different ways. Make sure that in the report you do not use the Grouping and Sorting functions because they will resort whatever sort you have as the recordsource.

Good luck

Bob Scriver

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top