PC Review


Reply
Thread Tools Rate Thread

cross tab chart filter using SQL

 
 
=?Utf-8?B?QWxleA==?=
Guest
Posts: n/a
 
      5th Jul 2005
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

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cross-Ref to Excel Chart mcalex Microsoft Word Document Management 6 12th Feb 2010 04:15 PM
cross tab filter form =?Utf-8?B?aXNtYWls?= Microsoft Access Queries 8 6th Feb 2006 03:11 PM
cross hatching and pie chart Cenk Ursavas via OfficeKB.com Microsoft Excel Charting 3 7th May 2005 01:04 AM
Cross tab query for chart Zegrath Microsoft Access Queries 1 26th Jan 2005 06:11 PM
Cross Tab Filter ? Scott Duncan Microsoft Access Queries 2 30th Sep 2004 02:34 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:04 PM.