I am attempting to setup a chart that allows the user some ability to customize their view. The problem is that I am not to familiar with the SeriesCollection command and I suspect that I am not using it correctly. To set the stage: upon startup, the chart (located at Forms!frmMain2.Form.frmStateAbbr.Form.frmChart1) is defaulted to show five columns. So far this works fine.
The user is then able to customize by clicking (or unclicking) checkboxes (located at at i.e. Forms!frmMain2.Form.frmStateAbbr.Form.chkBankruptcy). So if the user checks a box, in this example chkBankruptcy, it fires up the code (see below) in the AfterUpdate EP and the column chart now has an additional line chart.
Using this chkBankruptcy as an example, when I click on this checkbox the
code hangs on the line in RunChart: With [objChart].Object.SeriesCollection("Bankruptcy"). I can still F8 through this and allow the code to continue it's course.
Using chkForeclosure as a further example, when I click on this checkbox the code hangs on the line in RunChart: With [objChart].Object.SeriesCollection("Foreclosures"). I can still F8 through this allow the code to continue it's course.
Sorry for the long ramble, but I really really want to make this work and
hope that my explanation sheds some light on what my code problem may be.
Thank you for your assistance.
'---------------------- chkBankruptcy_AfterUpdate()----------
Private Sub chkBankruptcy_AfterUpdate()
Dim strSQL As String
'Verify that sum of data exists. If no data exists, aka SumOfRate=0 Then
' a msgbox tells user this and makes check box =0. If data exists then this
chkbox=1
' which will play a role in the module RunChart which is called.
If DSum("Rate", "tblChart1_MT", "Type='Bankruptcy'") = 0 Then
MsgBox "No data for Bankruptcy. Graph will not be altered"
Cancel = True
Me.chkBankruptcy = 0
Else
Call RunChart
End If
End Sub
'---------------------- RunChart----------
Function RunChart()
Dim strInclude As String
Dim strSQL As String
Dim objChart As Object
Set objChart = Forms!frmMain2.Form.frmStateAbbr.Form.frmChart1.Form.OLEUnbound0
'Redefining strSQL repopulates chart's datasheet with full collection of data
strSQL = "TRANSFORM Sum(qryChart1_MT.Rate) AS SumOfRate " & vbCrLf & _
"SELECT qryChart1_MT.DateYr " & vbCrLf & _
"FROM qryChart1_MT " & vbCrLf & _
"WHERE qryChart1_MT.Type " & vbCrLf & _
"GROUP BY qryChart1_MT.DateYr " & vbCrLf & _
"PIVOT qryChart1_MT.Type "
Debug.Print strSQL
Forms!frmMain2.Form.frmStateAbbr.Form.frmChart1.Form.OLEUnbound0.RowSource = strSQL
'The following If statements redefines strInclude that will narrow down the
'amount of fields associated with this chart's datasheet.
'This is a chkbox for this code but currently not enabled in form. It is there just in case
'the user wants to activate in future. It is defaulted on 1 and will always be
'part of strInclude.
If Forms!frmMain2.Form.frmStateAbbr.Form.chkDelDays3059 Then
strInclude = "'A1_DelinqDays3059',"
With [objChart].Object.SeriesCollection("A1_DelinqDays3059")
.type = xlColumn
.Interior.Color = vbRed
End With
End If
'This is a chkbox for this code but currently not enabled in form. It is there just in case
'the user wants to activate in future. It is defaulted on 1 and will always be
'part of strInclude.
If Forms!frmMain2.Form.frmStateAbbr.Form.chkDelDays6089 Then
strInclude = strInclude & "'A2_DelinqDays6089',"
With [objChart].Object.SeriesCollection("A2_DelinqDays6089")
.type = xlColumn
.Interior.Color = vbGreen
End With
End If
'This is a chkbox for this code but currently not enabled in form. It is there just in case
'the user wants to activate in future. It is defaulted on 1 and will always be
'part of strInclude.
If Forms!frmMain2.Form.frmStateAbbr.Form.chkDelDays90119 Then
strInclude = strInclude & "'A3_DelinqDays90119',"
With [objChart].Object.SeriesCollection("A3_DelinqDays90119")
.type = xlColumn
.Interior.Color = vbMagenta
End With
End If
'This is a chkbox for this code but currently not enabled in form. It is there just in case
'the user wants to activate in future. It is defaulted on 1 and will always be
'part of strInclude.
If Forms!frmMain2.Form.frmStateAbbr.Form.chkDelDays90Plus Then
strInclude = strInclude & "'A4_DelinqDays90Plus',"
With [objChart].Object.SeriesCollection("A4_DelinqDays90Plus")
.type = xlColumn
.Interior.Color = vbYellow
End With
End If
'This is a chkbox for this code but currently not enabled in form. It is there just in case
'the user wants to activate in future. It is defaulted on 1 and will always be
'part of strInclude.
If Forms!frmMain2.Form.frmStateAbbr.Form.chkDelDays120Plus Then
strInclude = strInclude & "'A5_DelinqDays120Plus',"
With [objChart].Object.SeriesCollection("A5_DelinqDays120Plus")
.type = xlColumn
.Interior.Color = vbCyan
End With
End If
'These next 14 If statements will run only if the user checks the chkbox
If Forms!frmMain2.Form.frmStateAbbr.Form.chk30YrFixed Then
strInclude = strInclude & "'30YrFixed',"
With [objChart].Object.SeriesCollection("30YrFixed")
.type = xlLine
.MarkerStyle = xlMarkerStylePlus
End With
End If
If Forms!frmMain2.Form.frmStateAbbr.Form.chkBankruptcy Then
strInclude = strInclude & "'Bankruptcy',"
With [objChart].Object.SeriesCollection("Bankruptcy") <Error Here>
.type = xlLine
.MarkerStyle = xlMarkerStylePlus
End With
End If
If Forms!frmMain2.Form.frmStateAbbr.Form.chkForeclosures Then
strInclude = strInclude & "'Foreclosures',"
With [objChart].Object.SeriesCollection("Foreclosures") <Error Here>
.type = xlLine
.MarkerStyle = xlMarkerStylePlus
End With
End If
' < Similar IF Statements >
If strInclude <> "" Then
' cuts off the last comma
strInclude = Left(strInclude, Len(strInclude) - 1)
' adds syntax we need
strInclude = "In(" & strInclude & ");"
End If
strSQL = strSQL & strInclude
Debug.Print strSQL
Forms!frmMain2.Form.frmStateAbbr.Form.frmChart1.Form.OLEUnbound0.RowSource = strSQL
Forms!frmMain2.Form.frmStateAbbr.Form.frmChart1.Form.OLEUnbound0.Refresh
End Function
The user is then able to customize by clicking (or unclicking) checkboxes (located at at i.e. Forms!frmMain2.Form.frmStateAbbr.Form.chkBankruptcy). So if the user checks a box, in this example chkBankruptcy, it fires up the code (see below) in the AfterUpdate EP and the column chart now has an additional line chart.
Using this chkBankruptcy as an example, when I click on this checkbox the
code hangs on the line in RunChart: With [objChart].Object.SeriesCollection("Bankruptcy"). I can still F8 through this and allow the code to continue it's course.
Using chkForeclosure as a further example, when I click on this checkbox the code hangs on the line in RunChart: With [objChart].Object.SeriesCollection("Foreclosures"). I can still F8 through this allow the code to continue it's course.
Sorry for the long ramble, but I really really want to make this work and
hope that my explanation sheds some light on what my code problem may be.
Thank you for your assistance.
'---------------------- chkBankruptcy_AfterUpdate()----------
Private Sub chkBankruptcy_AfterUpdate()
Dim strSQL As String
'Verify that sum of data exists. If no data exists, aka SumOfRate=0 Then
' a msgbox tells user this and makes check box =0. If data exists then this
chkbox=1
' which will play a role in the module RunChart which is called.
If DSum("Rate", "tblChart1_MT", "Type='Bankruptcy'") = 0 Then
MsgBox "No data for Bankruptcy. Graph will not be altered"
Cancel = True
Me.chkBankruptcy = 0
Else
Call RunChart
End If
End Sub
'---------------------- RunChart----------
Function RunChart()
Dim strInclude As String
Dim strSQL As String
Dim objChart As Object
Set objChart = Forms!frmMain2.Form.frmStateAbbr.Form.frmChart1.Form.OLEUnbound0
'Redefining strSQL repopulates chart's datasheet with full collection of data
strSQL = "TRANSFORM Sum(qryChart1_MT.Rate) AS SumOfRate " & vbCrLf & _
"SELECT qryChart1_MT.DateYr " & vbCrLf & _
"FROM qryChart1_MT " & vbCrLf & _
"WHERE qryChart1_MT.Type " & vbCrLf & _
"GROUP BY qryChart1_MT.DateYr " & vbCrLf & _
"PIVOT qryChart1_MT.Type "
Debug.Print strSQL
Forms!frmMain2.Form.frmStateAbbr.Form.frmChart1.Form.OLEUnbound0.RowSource = strSQL
'The following If statements redefines strInclude that will narrow down the
'amount of fields associated with this chart's datasheet.
'This is a chkbox for this code but currently not enabled in form. It is there just in case
'the user wants to activate in future. It is defaulted on 1 and will always be
'part of strInclude.
If Forms!frmMain2.Form.frmStateAbbr.Form.chkDelDays3059 Then
strInclude = "'A1_DelinqDays3059',"
With [objChart].Object.SeriesCollection("A1_DelinqDays3059")
.type = xlColumn
.Interior.Color = vbRed
End With
End If
'This is a chkbox for this code but currently not enabled in form. It is there just in case
'the user wants to activate in future. It is defaulted on 1 and will always be
'part of strInclude.
If Forms!frmMain2.Form.frmStateAbbr.Form.chkDelDays6089 Then
strInclude = strInclude & "'A2_DelinqDays6089',"
With [objChart].Object.SeriesCollection("A2_DelinqDays6089")
.type = xlColumn
.Interior.Color = vbGreen
End With
End If
'This is a chkbox for this code but currently not enabled in form. It is there just in case
'the user wants to activate in future. It is defaulted on 1 and will always be
'part of strInclude.
If Forms!frmMain2.Form.frmStateAbbr.Form.chkDelDays90119 Then
strInclude = strInclude & "'A3_DelinqDays90119',"
With [objChart].Object.SeriesCollection("A3_DelinqDays90119")
.type = xlColumn
.Interior.Color = vbMagenta
End With
End If
'This is a chkbox for this code but currently not enabled in form. It is there just in case
'the user wants to activate in future. It is defaulted on 1 and will always be
'part of strInclude.
If Forms!frmMain2.Form.frmStateAbbr.Form.chkDelDays90Plus Then
strInclude = strInclude & "'A4_DelinqDays90Plus',"
With [objChart].Object.SeriesCollection("A4_DelinqDays90Plus")
.type = xlColumn
.Interior.Color = vbYellow
End With
End If
'This is a chkbox for this code but currently not enabled in form. It is there just in case
'the user wants to activate in future. It is defaulted on 1 and will always be
'part of strInclude.
If Forms!frmMain2.Form.frmStateAbbr.Form.chkDelDays120Plus Then
strInclude = strInclude & "'A5_DelinqDays120Plus',"
With [objChart].Object.SeriesCollection("A5_DelinqDays120Plus")
.type = xlColumn
.Interior.Color = vbCyan
End With
End If
'These next 14 If statements will run only if the user checks the chkbox
If Forms!frmMain2.Form.frmStateAbbr.Form.chk30YrFixed Then
strInclude = strInclude & "'30YrFixed',"
With [objChart].Object.SeriesCollection("30YrFixed")
.type = xlLine
.MarkerStyle = xlMarkerStylePlus
End With
End If
If Forms!frmMain2.Form.frmStateAbbr.Form.chkBankruptcy Then
strInclude = strInclude & "'Bankruptcy',"
With [objChart].Object.SeriesCollection("Bankruptcy") <Error Here>
.type = xlLine
.MarkerStyle = xlMarkerStylePlus
End With
End If
If Forms!frmMain2.Form.frmStateAbbr.Form.chkForeclosures Then
strInclude = strInclude & "'Foreclosures',"
With [objChart].Object.SeriesCollection("Foreclosures") <Error Here>
.type = xlLine
.MarkerStyle = xlMarkerStylePlus
End With
End If
' < Similar IF Statements >
If strInclude <> "" Then
' cuts off the last comma
strInclude = Left(strInclude, Len(strInclude) - 1)
' adds syntax we need
strInclude = "In(" & strInclude & ");"
End If
strSQL = strSQL & strInclude
Debug.Print strSQL
Forms!frmMain2.Form.frmStateAbbr.Form.frmChart1.Form.OLEUnbound0.RowSource = strSQL
Forms!frmMain2.Form.frmStateAbbr.Form.frmChart1.Form.OLEUnbound0.Refresh
End Function