Current location: Hot Scripts Forums » Programming Languages » Visual Basic » Changing the Columns in a pivot table


Changing the Columns in a pivot table

Reply
  #1 (permalink)  
Old 01-13-06, 10:58 AM
Beth1 Beth1 is offline
Newbie Coder
 
Join Date: Jan 2006
Location: West Greenwich, RI USA
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Changing the Columns in a pivot table

Hi Below is my code. I am trying to take the columns JAN, FEB, MAR Ect. and make them variable based on Me.StartDate. So If a user typed in the date 8/1/2005 the first column would be August. I have a decent start here but I am not sure where my Case Statement should be to amke it work right can anyone help me?

If Me.StartDate = "" Or IsNull(Me.StartDate) Then
MsgBox "You must enter a start date"
Me.StartDate.SetFocus
Exit Sub
End If

If Me.End_Date = "" Or IsNull(Me.End_Date) Then
MsgBox "You must enter a end date"
Me.End_Date.SetFocus
Exit Sub
End If
Dim app As New Access.Application
Dim Rpt As Report
Dim ctl As Control
Dim strSQL As String
Dim db As Database
Dim qry As QueryDef
Set db = CurrentDb
Set qry = db.QueryDefs("qryincidentbymonth")

strSQL = "TRANSFORM Count(qryallstudy.STUDY_DETAIL_ID) AS CountOfSTUDY_DETAIL_ID SELECT qryallstudy.STUDY_DESC, Count(qryallstudy.STUDY_DETAIL_ID) AS [Total OfSTUDY_DETAIL_ID] FROM qryallstudy "
strSQL = strSQL & "WHERE (((qryallstudy.OCC_DATE) Between #" & Me.StartDate & "# And #" & Me.End_Date & "# )) "
strSQL = strSQL & "GROUP BY qryallstudy.STUDY_DESC PIVOT Format([OCC_DATE],""" & "mmm" & """) In (""" & "Jan" & """,""" & "Feb" & """,""" & "Mar" & """,""" & "Apr" & """,""" & "May" & """,""" & "Jun" & """,""" & "Jul" & """,""" & "Aug" & """,""" & "Sep" & """,""" & "Oct" & """,""" & "Nov" & """,""" & "Dec" & """));"

DoCmd.OpenReport "Incident by Month", acViewDesign

For Each Rpt In Reports
If Rpt.Name = "Incident by Month" Then
For Each ctl In Rpt.Controls
Select Case ctl
WHEN ctl.Name = "Jan_Label", ctl.Properties.Item("Caption") = "Jan"
Else
WHEN ctl.Name = "Feb_Label", ctl.Properties.Item("Caption") = "Feb"
Else
WHEN ctl.Name = "Mar_Label", ctl.Properties.Item("Caption") = "Mar"
Else
WHEN ctl.Name = "Apr_Label", ctl.Properties.Item("Caption") = "Apr"
Else
WHEN ctl.Name = "May_Label", ctl.Properties.Item("Caption") = "May"
Else
WHEN ctl.Name = "Jun_Label", ctl.Properties.Item("Caption") = "Jun"
Else
WHEN ctl.Name = "Jul_Label", ctl.Properties.Item("Caption") = "Jul"
Else
WHEN ctl.Name = "Aug_Label", ctl.Properties.Item("Caption") = "Aug"
Else
WHEN ctl.Name = "Sep_Label", ctl.Properties.Item("Caption") = "Sep"
Else
WHEN ctl.Name = "Oct_Label", ctl.Properties.Item("Caption") = "Oct"
Else
WHEN ctl.Name = "Nov_Label", ctl.Properties.Item("Caption") = "Nov"
Else
WHEN ctl.Name = "Dec_Label", ctl.Properties.Item("Caption") = "Dec"
End Select
Next
End If
Next
stDocName = "Incident by Month"
DoCmd.OpenReport stDocName, acPreview
End Sub
Reply With Quote
  #2 (permalink)  
Old 01-13-06, 03:00 PM
Beth1 Beth1 is offline
Newbie Coder
 
Join Date: Jan 2006
Location: West Greenwich, RI USA
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Iworked on my case statement but can not get it to work

For Each Rpt In Reports
If Rpt.Name = "Incident by Month" Then
Select Case Format(Me.StartDate, "mm")
Case "01"
ctl.Properties.Item("Caption") = "JAN"
ctl.Properties.Item("Caption") = "FEB"
ctl.Properties.Item("Caption") = "MAR"
ctl.Properties.Item("Caption") = "APR"
ctl.Properties.Item("Caption") = "MAY"
ctl.Properties.Item("Caption") = "JUN"
ctl.Properties.Item("Caption") = "JUL"
ctl.Properties.Item("Caption") = "AUG"
ctl.Properties.Item("Caption") = "SEP"
ctl.Properties.Item("Caption") = "OCT"
ctl.Properties.Item("Caption") = "NOV"
ctl.Properties.Item("Caption") = "DEC"
Case "02"
ctl.Properties.Item("Caption") = "FEB"
ctl.Properties.Item("Caption") = "MAR"
ctl.Properties.Item("Caption") = "APR"
ctl.Properties.Item("Caption") = "MAY"
ctl.Properties.Item("Caption") = "JUN"
ctl.Properties.Item("Caption") = "JUL"
ctl.Properties.Item("Caption") = "AUG"
ctl.Properties.Item("Caption") = "SEP"
ctl.Properties.Item("Caption") = "OCT"
ctl.Properties.Item("Caption") = "NOV"
ctl.Properties.Item("Caption") = "DEC"
ctl.Properties.Item("Caption") = "JAN"
End
End If
Next
stDocName = "Incident by Month"
DoCmd.OpenReport stDocName, acPreview
End Sub
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with a sort table js function tdubyou JavaScript 0 05-03-04 09:19 AM
Print MySQL resultset to five columns HTML-table morrowind PHP 1 05-03-04 08:13 AM
auto table resize derick_2k JavaScript 4 04-26-04 02:32 PM
Changing a color on a table row one at a time. mtilori HTML/XHTML/XML 3 02-24-04 04:27 PM
changing table properties with ALTER TABLE Squid44th PHP 1 02-24-04 03:29 PM


All times are GMT -5. The time now is 01:15 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.