PDA

View Full Version : Sleeper: Need help with code to controll itemsvisibility in datafield/pivottable



RichNL
02-19-2005, 10:19 AM
maybe somebody can help me?

After deleting the combobox selection every item dissapears.
This is caussing an error.

Also the code needs some adjustment because in the first for/next loop the items visible property's are set to show all the "days off one month".
Then by changing the month in the combobox all off the items will first be set to false and the pivotitems "visibilityproperty can not be retrieved error" comes up again.
Once again it is causing an error because excel doesn't like it if all the data is gone.
(same as the first part)
Y understand why this happens but not how to avoid it.

This is my code:


Private Sub ComboBox1_Change()
'after deleting/changing the combobox selection - the dateitems based
'on a radiobutton.value("months" or "days off month") should not dissapear
'or cause an error
'manual input should also be possible with data validation!!!!!!!
Dim i As PivotItem
Dim showmonth As Variant
Dim pvi As PivotItems
Set pvi = ActiveSheet.PivotTables("Draaitabelkasboek").PivotFields("Datum").PivotItems
showmonth = ActiveSheet.ComboBox1.Value
Application.ScreenUpdating = False
If kzrMaanden.Value = False Then
Goto TheOtherRadiobutton
Else
For Each i In pvi
If i.Value = showmonth Then
i.Visible = True
Else
i.Visible = False
End If
Next i
End If
Exit Sub
TheOtherRadiobutton:
'Checks every item in PivotFields("Datum")and hides items if neccesary
For Each i In pvi
If Format(i.Value,"mmm") = showmonth Then
i.Visible = True
Else
i.Visible = False
End If
Next i
End Sub

i'am truly gratefull if somebody has a solution
Richnl (beginner)