Ark68
Well-known Member
- Joined
- Mar 23, 2004
- Messages
- 4,564
- Office Version
- 365
- 2016
- Platform
- Windows
I have a userform with 4 toggle buttons on it
With each button I have an on '_Click' event.
When the user form initializes all 4 buttons are deselected (in their false state). Suppose the user selects the tglb_hp_flds button. The button is depressed (now in true state), and the CLICK routine is executed which executes the 'toggleclicks1' routine.
Everything works as expected.
However, an issue arises when the user then selects the tglb_hp_dias button. The button depresses (now in the true state), and the previously selected button also remains in the depressed (true) position. (as expected)
The 'toggleclicks1' is again executed. It moves through the ifs until it hits 'tglb_hp_dias.Value = True Then", and proceeds to execute it's respective commands. To return the previously selected tglb_hp_flds button back to its default FALSE state, the code executes 'Me.tglb_hp_flds.Value = False'. But when it does this ... it seems to equate to a CLICK, thus executing the 'Sub tglb_hp_flds_Click()' routine.
My process of resetting previously selected buttons in their TRUE state back to FALSE is triggering CLICK routines, appearing to result in a loop of unwanted behaviour.
Is this normal behaviour when coding a value change to a toggle button, to mimick a CLICK? If so, what do I need to do to avoid this?
With each button I have an on '_Click' event.
Code:
Private Sub tglb_hp_crts_Click()
toggleclicks1
End Sub
Private Sub tglb_hp_dias_Click()
toggleclicks1
End Sub
Private Sub tglb_hp_flds_Click()
toggleclicks1
End Sub
Private Sub tglb_hp_others_Click()
toggleclicks1
End Sub
Code:
Private Sub toggleclicks1()
Dim scrit5 As String
Dim scrit10 As String
Dim dirflag As Long
Dim raf1_criteria As Range
If Me.MultiPage1.Value = 0 Then 'ALL PAGE BUTTONS
'... code ...
ElseIf Me.MultiPage1.Value = 2 Then 'HILLSIDE PAGE BUTTONS
Set lbtarget = Me.hp_list
scrit10 = "HP"
If tglb_hp_dias.Value = True Then 'HILLSIDE DIAMONDS ACTIVATED
scrit5 = "=D*"
dirflag = 0
Me.tglb_hp_flds.Value = False
Me.tglb_hp_crts.Value = False
Me.tglb_hp_others.Value = False
ElseIf tglb_hp_flds.Value = True Then 'HILLSIDE FIELDS ACTIVATED
scrit5 = "=F*"
dirflag = 0
Me.tglb_hp_dias.Value = False
Me.tglb_hp_crts.Value = False
Me.tglb_hp_others.Value = False
ElseIf tglb_hp_crts.Value = True Then 'HILLSIDE COURTS ACTIVATED
scrit5 = "=C*"
dirflag = 0
Me.tglb_hp_dias.Value = False
Me.tglb_hp_flds.Value = False
Me.tglb_hp_others.Value = False
ElseIf tglb_hp_others.Value = True Then 'HILLSIDE OTHERS ACTIVATED
Set raf1_criteria = ws_vh.Range("B6:E7")
ws_vh.Range("E7") = "HP"
dirflag = 1
Me.tglb_hp_dias.Value = False
Me.tglb_hp_flds.Value = False
Me.tglb_hp_crts.Value = False
Else ' all HILLSIDE BUTTONS FALSE
scrit5 = "<>"
dirflag = 0
Me.tglb_hp_dias.Value = False
Me.tglb_hp_flds.Value = False
Me.tglb_hp_crts.Value = False
Me.tglb_hp_others.Value = False
End If
' ... code ...
End If
With ws_core
.Activate '''
.Range("A:W").EntireColumn.Hidden = False
.AutoFilterMode = False
If dirflag = 0 Then
.Range("A1:V1").AutoFilter Field:=5, Criteria1:=scrit5
.Range("A1:V1").AutoFilter Field:=10, Criteria1:=scrit10
Else
.Range("A:V").AdvancedFilter _
Action:=xlFilterInPlace, _
CriteriaRange:=raf1_criteria
End If
.Range("B:B,D:D,G:G,I:J,M:M,P:V").EntireColumn.Hidden = True
Set Rnglist = .Range("A1:O" & .Cells(Rows.Count, "A").End(xlUp).Row).SpecialCells(xlCellTypeVisible)
End With
With ws_th
.Activate '''
.Cells.ClearContents
Rnglist.Copy ws_th.Range("A1")
End With
llstrow = ws_th.Cells(Rows.Count, 1).End(xlUp).Row
Set rngSource = ws_th.Range("A2:G" & llstrow)
With lbtarget
.Clear
.ColumnCount = 9
.ColumnWidths = "50;40;20;200;125;50;50;50;50"
For Each oneRow In rngSource.Rows
.AddItem oneRow.Range("A1").Text
.List(.ListCount - 1, 1) = oneRow.Range("B1").Text
.List(.ListCount - 1, 2) = oneRow.Range("C1").Text
.List(.ListCount - 1, 3) = oneRow.Range("D1").Text
.List(.ListCount - 1, 4) = oneRow.Range("E1").Text
.List(.ListCount - 1, 5) = oneRow.Range("F1").Text
.List(.ListCount - 1, 6) = oneRow.Range("G1").Text
.List(.ListCount - 1, 7) = oneRow.Range("H1").Text
.List(.ListCount - 1, 8) = oneRow.Range("I1").Text
Next oneRow
End With
End Sub
When the user form initializes all 4 buttons are deselected (in their false state). Suppose the user selects the tglb_hp_flds button. The button is depressed (now in true state), and the CLICK routine is executed which executes the 'toggleclicks1' routine.
Everything works as expected.
However, an issue arises when the user then selects the tglb_hp_dias button. The button depresses (now in the true state), and the previously selected button also remains in the depressed (true) position. (as expected)
The 'toggleclicks1' is again executed. It moves through the ifs until it hits 'tglb_hp_dias.Value = True Then", and proceeds to execute it's respective commands. To return the previously selected tglb_hp_flds button back to its default FALSE state, the code executes 'Me.tglb_hp_flds.Value = False'. But when it does this ... it seems to equate to a CLICK, thus executing the 'Sub tglb_hp_flds_Click()' routine.
My process of resetting previously selected buttons in their TRUE state back to FALSE is triggering CLICK routines, appearing to result in a loop of unwanted behaviour.
Is this normal behaviour when coding a value change to a toggle button, to mimick a CLICK? If so, what do I need to do to avoid this?