cross tab chart filter using SQL

A

Alex

I am using code to set the filter for a query that is populating my chart in
my report. I'm using code so that users can choose more than one option in a
list box as a query parameter.

When I have a select query, this method works fine, but now I need to set
the filter for a crosstab query and I'm getting an error message: syntax
error in TRANSFORM statement. I'm hoping that I can filter a crosstab query
using this method like I can a select query and that I just have the
qdf_Chart.sql syntax written correctly. Thanks in advance for your input.

Private Sub OpenChart_Click()
Dim db As DAO.Database
Dim qdf_Chart As DAO.QueryDef
Dim adf_Unfiltered As DAO.QueryDef
Dim sql1 As String
Dim sql2 As String
Dim VarItem As Variant
Dim StrGender As String
Dim datBegin As Date
Dim datEnd As Date
Dim StrFilter As String
Dim StrFilterChart

Set db = CurrentDb
Set qdf_Unfiltered = db.QueryDefs("ChartCrossTab")
Set qdf_Chart = db.QueryDefs("ChartCrossTab")

'Open Report
If SysCmd(acSysCmdGetObjectState, acReport, "AttritionReportChart") <>
acObjStateOpen Then
DoCmd.OpenReport "AttritionReportChart", acViewPreview
End If

'Build Criteria string from Gender Listbox
For Each VarItem In Me.cmdGender.ItemsSelected
StrGender = StrGender & ",'" & Me.cmdGender.ItemData(VarItem) & "'"
Next VarItem
If Len(StrGender) = 0 Then
StrGender = "Like'*'"
Else
StrGender = Right(StrGender, Len(StrGender) - 1)
StrGender = "IN(" & StrGender & ")"
End If

'Build filter string [name] is the query field name
StrFilter = "[GenderDesc]" & StrGender

'Apply the filter and switch it on
With Reports![AttritionReportChart]
..Filter = StrFilter
..FilterOn = True
..AttritionReportChartTitle.Value = "Attrition Report for " & Me.cmdGender
End With

qdf_Chart.SQL = "TRANSFORM Count
AttritionQuery.RetirementVoluntaryorInvoluntary)AS
CountOfRetirementVoluntaryorInvoluntary" & _
"SELECT AttritionQuery.PSReasonCodeDesc, AttritionQuery.GenderDesc FROM
AttritionQuery WHERE" & StrFilter & _
"GROUP BY AttritionQuery.PSReasonCodeDesc, AttritionQuery.GenderDesc,
AttritionQuery.RetirementVoluntaryorInvoluntary, AttritionQuery.Group,
AttritionQuery.GenderDesc, AttritionQuery.PSReasonCodeDesc PIVOT
AttritionQuery.Code"


End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top