Hi all,
I'm trying to do some "tidying up" in my database application.
One of the things I'd like to do is reduce the number of reports. Many are copies that just vary by sort order.
As an example, I have two cookout reports that are identical except the sort order. One sorts by UnitID then by Day and the other sorts by Day and then UnitID. I know I could just use VBA open one report or the other, but I realized when I made changes to one report and not the other that it sure would be nice to have just one report with the sort option passed to it.
Unfortunately, everyplace I've looked has things like "and then you can pass this string to the report using Open Args" or "the Order By property is over-ruled by the sort of the query" or something else I can't wrap my brain around. Or, it just talks about using the Group/Sort options within the report.
I'm sure it's doable with VBA, I just can't figure out how!
So far, on my form I have:
Code:
Private Sub cmdCookoutDays_Click()
Dim optGroup As Integer
Dim rptName As String
Dim sortField1 As String
Dim sortField2 As String
Dim strSort As String
optGroup = ogCOSortOrder 'name of option group so it can be changed for other reports
rptName = "rpt Cookout Days" 'name of report so it can be changed later
If optGroup = 1 Then
sortField1 = "UnitID"
sortField2 = "Day"
Else
sortField1 = "Day"
sortField2 = "UnitID"
End If
strSort = sortField1 & ", " & sortField2 'strSort = sortField1, sortField2
DoCmd.OpenReport rptName, acViewReport
End Sub
Now, what do I do with the strSort string?
The way the report is set up currently is with no sorting and "Order By On Load" set to "yes". I've seen mention of using OpenArgs in the Order By property, but ... how?
I'm sure I'm missing something really basic here ...
Susie
Girl Scout volunteer
Kansas