krossview
Chemical
- Mar 4, 2002
- 40
I've developed a VB macro display a form to quickly hide and unhide columns in a large sheet. The value of the check box is toggled to TRUE or FALSE for each column. A FOR loop then shows or hides each column in the sheet.
The code for Hide/Unhiding a single column works fine,
' Hide/Unhide a Single column
Private Sub CheckBox1_Click()
CheckBox1.Value = Not CheckBox1.Value
End Sub
' Hide/Unhide a Group of columns
Private Sub cmbTotal_Click()
CheckBox1.Value = Not CheckBox1.Value
CheckBox2.Value = Not CheckBox2.Value
CheckBox3.Value = Not CheckBox3.Value
End Sub
But a problem occurs when I want to hide/unhide a bunch of similar columns as group with a command button.
As soon it executes the 1st code line in the cmbTotal command button it then calls the CheckBox1 routine, which in turn sets up a recursive call to the CheckBox1 routine. Result is that the macro now hangs!!!!![[sleeping] [sleeping] [sleeping]](/data/assets/smilies/sleeping.gif)
I believe its the Event CLICK that causes this problem as everytime the value of the checkbox changes VB sees it as an Event. Using the NOT statement is a very simple way of toggling the checkbox value, but it there a way to stop the Event CLICK recursive calls. Pls advise or easier way to do this.
Also, what code do I use to loop through all the checkboxes on the form using the FOR EACH statement instead of hardcoding each checkbox in the FOR loop.![[thumbsup2] [thumbsup2] [thumbsup2]](/data/assets/smilies/thumbsup2.gif)
Any help is greatly appreciated.![[wavey] [wavey] [wavey]](/data/assets/smilies/wavey.gif)
Krossview /OK
The code for Hide/Unhiding a single column works fine,
' Hide/Unhide a Single column
Private Sub CheckBox1_Click()
CheckBox1.Value = Not CheckBox1.Value
End Sub
' Hide/Unhide a Group of columns
Private Sub cmbTotal_Click()
CheckBox1.Value = Not CheckBox1.Value
CheckBox2.Value = Not CheckBox2.Value
CheckBox3.Value = Not CheckBox3.Value
End Sub
But a problem occurs when I want to hide/unhide a bunch of similar columns as group with a command button.
As soon it executes the 1st code line in the cmbTotal command button it then calls the CheckBox1 routine, which in turn sets up a recursive call to the CheckBox1 routine. Result is that the macro now hangs!!!!
![[sleeping] [sleeping] [sleeping]](/data/assets/smilies/sleeping.gif)
I believe its the Event CLICK that causes this problem as everytime the value of the checkbox changes VB sees it as an Event. Using the NOT statement is a very simple way of toggling the checkbox value, but it there a way to stop the Event CLICK recursive calls. Pls advise or easier way to do this.
Also, what code do I use to loop through all the checkboxes on the form using the FOR EACH statement instead of hardcoding each checkbox in the FOR loop.
![[thumbsup2] [thumbsup2] [thumbsup2]](/data/assets/smilies/thumbsup2.gif)
Any help is greatly appreciated.
![[wavey] [wavey] [wavey]](/data/assets/smilies/wavey.gif)
Krossview /OK