SteveL13
asked on
Trying to filter a sub-report
I'm using this code to filter the results in a sub-report. But it gets "stuck" on the line, "Me.Filter = "[Agent] = '" & strAgent & "'""
Also, I'm not sure if it belongs in the onopen or onload event.
Here is my code:
Also, I'm not sure if it belongs in the onopen or onload event.
Here is my code:
Private Sub Report_Open(Cancel As Integer)
If DLookup("[SecurityLevel]", "LOCALtblCurrentUser") > 1 Then
Dim strAgent As String
strAgent = DLookup("CurrentUser", "LOCALtblCurrentUser")
Me.Filter = "[Agent] = '" & strAgent & "'"
FilterOn = True
Else
DoCmd.OpenReport "rptReferrals", acViewPreview, "", "", acNormal
End If
End Sub
You need to set your filter ON:
Me.Filter = "[Agent] = '" & strAgent & "'"
Me.FilterOn = True
/gustav
But your code doesn't make much sense ... you are opening a new report in the OnLoad event of a subform ... not very likely what you wish.
/gustav
/gustav
I am sure Gustav can get you sorted...
ASKER
I am opening a report via a command button on a form. The code behind the command button is:
But then I am trying to open the subreport using the same filter with this revised onclick code and it is not working:
I do not know how to filter the sub-report using the same criteria.
Dim Agent As String
Dim WhereCondition As String
Agent = Nz(DLookup("[CurrentUser]", "LOCALtblCurrentUser"))
WhereCondition = "[Agent] = '" & Agent & "'"
DoCmd.OpenReport "rptReferrals", acViewPreview, , WhereCondition, acWindowNormal
But then I am trying to open the subreport using the same filter with this revised onclick code and it is not working:
Dim Agent As String
Dim WhereCondition As String
Agent = Nz(DLookup("[CurrentUser]", "LOCALtblCurrentUser"))
WhereCondition = "[Agent] = '" & Agent & "'"
Reports!rptReferrals.Report!subrptReferralCounts.Filter = "[Agent] = '" & Agent & "'"
Me.FilterOn = True
DoCmd.OpenReport "rptReferrals", acViewPreview, , WhereCondition, acWindowNormal
I do not know how to filter the sub-report using the same criteria.
The first is correct.
The second you could solve extremely easy by setting the Master/Child link fields of the subreport control of the main report to [Agent]
/gustav
The second you could solve extremely easy by setting the Master/Child link fields of the subreport control of the main report to [Agent]
/gustav
ASKER
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Worked:
Dim Agent As String
Dim WhereCondition As String
Agent = Nz(DLookup("[CurrentUser]" , "LOCALtblCurrentUser"))
WhereCondition = "[Agent] = '" & Agent & "'"
DoCmd.OpenReport "rptReferrals", acViewPreview, , WhereCondition, acWindowNormal
Reports!rptReferrals.Repor t!subrptRe ferralCoun ts.Report. Filter = "[Agent] = '" & Agent & "'"
Reports!rptReferrals.Repor t!subrptRe ferralCoun ts.Report. FilterOn = True
Dim Agent As String
Dim WhereCondition As String
Agent = Nz(DLookup("[CurrentUser]"
WhereCondition = "[Agent] = '" & Agent & "'"
DoCmd.OpenReport "rptReferrals", acViewPreview, , WhereCondition, acWindowNormal
Reports!rptReferrals.Repor
Reports!rptReferrals.Repor
I am not quite sure of your code there, ...perhaps another Expert can help there..
But try it like this, ..as a quick test
"[Agent] =" & "'" & strAgent & "'"