Reputation: 27
Good afternoon all
I have this piece of code to check if the checkboxes of my form are not checked, but each time I have this error message: runtime error '438'
Private Sub Btn_Send_Click()
Dim ctl As Control
Dim iX As Integer
For Each ctl In Me.Controls
If TypeName(ctl) = "CheckBox" And ctl.Value = False Then iX = iX + 1
Next ctl
If iX = 0 Then MsgBox "No checkBox Selected", vbExclamation, "Title"
End Sub
Debbuging error :
If TypeName(ctl) = "CheckBox" And ctl.Value = False Then
Run-Time Error #438: Object doesn't support this property or method
Thank you for your help
Upvotes: 1
Views: 1568
Reputation: 43575
Try to do it like this:
For Each ctl In Me.Controls
If TypeName(ctl) = "CheckBox" Then
If ctl.Value = False Then
iX = iX + 1
End If
End If
Next ctl
The reason is that VBA does not support short-circuit evaluation - Does the VBA "And" operator evaluate the second argument when the first is false?
Thus, even that your first condition is False
it nicely goes and checks for your second condition. And if it is not a CheckBox
control, then it throws an error, because it does not have a .Value
property.
Upvotes: 2