Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change Column Headings property in Crosstab Query w/ VB

Status
Not open for further replies.

mystuff

Programmer
Apr 30, 2004
86
0
0
US
Is it possible to change the Column Headings property in a Crosstab Query using VB?

Thanks.

 
Code:
TRANSFORM Sum(Issue.Amount) AS SumOfAmount
SELECT Issue.ItemName
FROM Issue
GROUP BY Issue.ItemName
PIVOT Format([IssueDate],"yyyy");

Code:
TRANSFORM Sum(Issue.Amount) AS SumOfAmount
SELECT Issue.ItemName
FROM Issue
GROUP BY Issue.ItemName
PIVOT Format([IssueDate],"yyyy") [b][COLOR=red]In (2003,2004,2005)[/color][/b];
First one is a crosstab query without defined column heading and second with defined as years 2003,2004 & 2005.
You can split this into VBA like below. You will be able to change it as you required.

Code:
Sub LoadList()
    Dim strSQL As String
    strSQL = "TRANSFORM Sum(Issue.Amount) AS SumOfAmount SELECT Issue.ItemName FROM Issue GROUP BY Issue.ItemName " & Me.TxtHeadings.Value
    Me.List0.RowSource = strSQL
End Sub
[COLOR=green]'=====================================[/color]
Private Sub cmdLoadList_Click()
    LoadList
End Sub
[COLOR=green]'===================================[/color]
Private Sub Form_Load()
    Me.TxtHeadings.Value = "PIVOT Format([IssueDate],'yyyy')In(2003,2004,2005,2006)"
End Sub
ComeBack if you need more help.

________________________________________
Zameer Abdulla
Visit Me
A child may not be able to lift too much.
But it can certainly hold a marriage together
 
I have usually just added a source to the query with the "Column Headings" desired. You can mkae it an Outter Join to the desired Piviot Column and use it as the actual piviot column, thus creating the headings w/o any code.

You DO need to take care that the new source includes all of the desired (or possible) values (depending on the desired results), otherwise is is trivially possible to exclude (valid & meaningful) information - - - which would skew the results and possibly harm your standing.





MichaelRed


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top