Advertisement

09.10.2008 at 01:29PM PDT, ID: 23720819
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.0

How do I pass Filter and OrderBy from SubForm to Report?

Asked by DWYee in Access Reports

Tags:

I'm tring to get a Report to sort (OrderBy) AND Filter (Filter) the same way that the user may have specified in the datasheet view in fSubFilingCalendar. (Clicking on the little down arrow in the column header & selecting a sort by or checking the checkboxes in the filter.)  I'm opening the report "Filing Calendar Report 1" using a button on the main form "Filing_Calendar", which fires up a macro that does the "OpenReport" action with these arguments: " Filing Calendar Report 1, Report, , , Normal".

The Report has a "Private Sub Report_Load()" subroutine that is building a sql query to pass as the recordsource to the report: "Report.RecordSource = strSQL".  I've tried adding to the end of the sql query's WHERE clause:

" AND " & [Forms]![Filing_Calendar].fSubFilingCalendar.Form.Filter & "

And also have tried ending the sql query:

"ORDER BY " & [Forms]![Filing_calendar].fSubFilingCalendar.Form.OrderBy

But the report seems to have a mind of its own and ignores the ORDER BY and the filter part of the WHERE.

So, I've tried putting in the 'Filter Name' Action Arguments slot at the bottom of the Macro Tools window of the macro that opens the Report:

"=[Forms]![Filing_Calendar]![fSubFilingCalendar].[Form].[OrderBy]"

or:

"[Forms]![Filing_Calendar]![fSubFilingCalendar].[Form].[OrderBy]" (with and without the '=').

I've also tried the same items in the 'Where Condition" slot. No go!

Finally, in the Visual Basic code for the report, in the "Private Sub Report_Load()" I have tried the following, one at a time:
1)      With Reports("Filing Calendar Report 1")
            .Filter = [Forms]![Filing_Calendar].fSubFilingCalendar.Form.Filter
            .OrderBy = [Forms]![Filing_Calendar].fSubFilingCalendar.Form.OrderBy
      End With

2)      Dim strFilter As String
      Dim strOrderBy As String
      Dim lengthFilter As Integer
      Dim lengthOrderBy As Integer
      Dim spot As Integer

      strFilter = [Forms]![Filing_Calendar].fSubFilingCalendar.Form.Filter
      lengthFilter = Len(strFilter)
      If lengthFilter > 0 Then
            spot = InStrRev(strFilter, ".")
            strFilter = Trim(Left(Right(strFilter, lengthFilter - spot), (lengthFilter - spot) - 1))
      End If

      spot = 0
      strOrderBy = [Forms]![Filing_Calendar].fSubFilingCalendar.Form.OrderBy
      lengthOrderBy = Len(strOrderBy)
      If lengthOrderBy > 0 Then
            spot = InStrRev(strOrderBy, ".")
            strOrderBy = Trim(Right(strOrderBy, lengthOrderBy - spot))
      End If

      With Reports("Filing Calendar Report 1")
            .Filter = strFilter
            .OrderBy = strOrderBy
      End With

3) In the Design View of the Report, at the bottom, in the "Group, Sort, and Total" window, 'Sort By Expression', I have put "=[Forms]![Filing_Calendar]![fSubFilingCalendar].[Form].[OrderBy]"

4)  Dim strCompleteOrderBy As String
    Dim strCompleteFilter As String
      strCompleteOrder = [Forms]![Filing_Calendar].fSubFilingCalendar.Form.OrderBy
      strCompleteFilter = [Forms]![Filing_Calendar].fSubFilingCalendar.Form.Filter

      Report.OrderBy = strCompleteOrderBy
    Me.OrderByOn = True
    Report.Filter = strCompleteFilter
    Me.FilterOn = True
    Report.RecordSource = strSQL

By the way, I have set the "Filter On Load" and "Order By On Load" properties of the report to "Yes" Or "No", without making any difference.

None of the above works. What exactly is the report looking for and how do I give it both OrderBy and Filter parameters (also, if more than one filter and order by is specified)? Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
Option Compare Database
 
Private Sub btnClose_Click()
    DoCmd.Close
End Sub
 
Private Sub Report_Load()
    Dim enterprise_id As Integer
    Dim company_id As Integer
    Dim analyst_id As Integer
    Dim beginDate As String
    Dim endDate As String
    Dim show_complete As Boolean
    Dim show_incomplete As Boolean
    Dim strSQL As String
    Dim strFilter As String
    Dim strOrderBy As String
    Dim lengthFilter As Integer
    Dim lengthOrderBy As Integer
    Dim spot As Integer
    Dim args As String
    Dim strCompleteOrderBy As String
    Dim strCompleteFilter As String
    
    strFilter = [Forms]![Filing_Calendar].fSubFilingCalendar.Form.Filter
    strCompleteFilter = strFilter
    lengthFilter = Len(strFilter)
    If lengthFilter > 0 Then
        args = strFilter
        spot = InStrRev(strFilter, ".")
        strFilter = Trim(Left(Right(strFilter, lengthFilter - spot), (lengthFilter - spot) - 1))
    End If
    
    spot = 0
    strOrderBy = [Forms]![Filing_Calendar].fSubFilingCalendar.Form.OrderBy
    strCompleteOrderBy = strOrderBy
    lengthOrderBy = Len(strOrderBy)
    If lengthOrderBy > 0 Then
        If lengthFilter > 0 Then
            args = args & "," & strOrderBy
        Else
            args = strOrderBy
        End If
        spot = InStrRev(strOrderBy, ".")
        strOrderBy = Trim(Right(strOrderBy, lengthOrderBy - spot))
    End If
        
        
    With Reports("Filing Calendar Report 1")
        .Filter = [Forms]![Filing_Calendar].fSubFilingCalendar.Form.Filter
        '.Filter = strFilter
        .OrderBy = [Forms]![Filing_Calendar].fSubFilingCalendar.Form.OrderBy
        '.OrderBy = strOrderBy
    End With
 
    [Forms]![Filing_Calendar]!txtBeginDate.SetFocus
    If [Forms]![Filing_Calendar]!txtBeginDate.Text <> "" Then
        beginDate = [Forms]![Filing_Calendar]!txtBeginDate.Text
    End If
    [Forms]![Filing_Calendar]!txtEndDate.SetFocus
    If [Forms]![Filing_Calendar]!txtEndDate.Text <> "" Then
        endDate = [Forms]![Filing_Calendar]!txtEndDate.Text
    End If
    
        strSQL = "SELECT filing_detail.filing_detail_id,state.abbreviation, filing_jurisdiction.filing_jurisdiction_name, filing_jurisdiction.filing_jurisdiction_id, filing_detail.tax_year, filing_detail.return_due_date, filing_detail.return_approved, filing_detail.who_approved, filing_detail.mail_date, filing_detail.certified, filing_detail.extension_filed, filing_detail.extended_due_date, enterprise.enterprise_name, company.company_name, site.site_name,site.site_id,site.site_code, analyst.last_name, analyst.first_name " & _
            " FROM ((enterprise INNER JOIN company ON enterprise.[enterprise_id] = company.[enterprise_id])" & _
            " INNER JOIN (site INNER JOIN ((state INNER JOIN filing_jurisdiction ON state.[state_id] = filing_jurisdiction.[state_id])" & _
            " INNER JOIN filing_detail ON filing_jurisdiction.[filing_jurisdiction_id] = filing_detail.[filing_jurisdiction_id]) ON site.[site_id] = filing_detail.[site_id]) ON company.[company_id] = site.[company_id])" & _
            " LEFT JOIN (analyst_company LEFT JOIN  analyst ON analyst.[analyst_id] = analyst_company.[analyst_id]) ON company.[company_id] = analyst_company.[company_id]"
        
        If [Forms]![Filing_Calendar].chkShowIncomplete = True And [Forms]![Filing_Calendar].chkShowComplete = False Then
            strSQL = strSQL & " WHERE filing_detail.return_approved=false"
        End If
        If [Forms]![Filing_Calendar].chkShowIncomplete = False And [Forms]![Filing_Calendar].chkShowComplete = True Then
            strSQL = strSQL & " WHERE filing_detail.return_approved=true"
        End If
        If [Forms]![Filing_Calendar].chkShowIncomplete = True And [Forms]![Filing_Calendar].chkShowComplete = True Then
            strSQL = strSQL & " WHERE filing_detail.return_approved=true OR filing_detail.return_approved=false"
        End If
        If [Forms]![Filing_Calendar].cboEnterprise <> "" Then
            strSQL = strSQL & " AND enterprise.enterprise_id=" & [Forms]![Filing_Calendar]!cboEnterprise & ""
        End If
        If [Forms]![Filing_Calendar].cboCompany <> "" Then
            strSQL = strSQL & " AND company.company_id=" & [Forms]![Filing_Calendar]!cboCompany & " AND site.company_id=" & [Forms]![Filing_Calendar]!cboCompany & ""
        End If
        If [Forms]![Filing_Calendar].cboAnalyst <> "" Then
            strSQL = strSQL & " AND analyst_company.analyst_id=" & [Forms]![Filing_Calendar]!cboAnalyst & ""
        End If
        If [Forms]![Filing_Calendar].cboState <> "" Then
            strSQL = strSQL & " AND filing_jurisdiction.state_id=" & [Forms]![Filing_Calendar]!cboState
        End If
        If [Forms]![Filing_Calendar].cboTaxYear <> "" Then
            strSQL = strSQL & " AND filing_detail.tax_year=" & [Forms]![Filing_Calendar]!cboTaxYear
        End If
        If lengthFilter > 0 Then
            strSQL = strSQL & " AND " & strFilter
        End If
        If beginDate <> "" And endDate <> "" Then
            strSQL = strSQL & " AND filing_detail.return_due_date >=#" & beginDate & "# AND filing_detail.return_due_date <=#" & endDate & "#"
        End If
        If lengthOrderBy > 0 Then
            strSQL = strSQL & " ORDER BY " & strOrderBy
        Else
            strSQL = strSQL & " ORDER BY enterprise.enterprise_name,company.company_name,site.site_name,filing_detail.return_due_date ASC;"
        End If
    
    Report.OrderBy = strCompleteOrderBy
    Me.OrderByOn = True
    Report.Filter = strCompleteFilter
    Me.FilterOn = True
    Report.RecordSource = strSQL
End Sub
[+][-]09.11.2008 at 08:07AM PDT, ID: 22450735

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.11.2008 at 08:20AM PDT, ID: 22450897

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Access Reports
Tags: Access 2007
Sign Up Now!
Solution Provided By: DWYee
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20081112-EE-VQP-44 / EE_QW_2_20070628