I need to set a property False value & ForeColor to all controls on a UserForm from a macro outside the code of that UserForm.
The userform are shown as (vbModeless
).
The below code without using (On Error Resume Next) is producing this error:
Run-time error '438': Object doesn't support this property or method
At these lines ctrl.Value = False
& ctrl.ForeColor = vbBlack
But, If I used the not recommended (On Error Resume Next), then the code works successfully.
Sub Clear_All_Filter()
On Error Resume Next
Dim ctrl As control
For Each ctrl In UserForm1.Controls
ctrl.Value = False
ctrl.ForeColor = vbBlack
Next
End Sub
CodePudding user response:
Most likely you have a label-control that doesn't support value
.
Check for the type of the control within your loop:
Sub Clear_All_Filter()
Dim ctrl As Control
For Each ctrl In UserForm1.Controls
If TypeName(ctrl) <> "Label" Then
ctrl.Value = False
ctrl.ForeColor = vbBlack
End If
Next
End Sub