I have a section of code that evaluates the state of several check boxes. The first group I am calling "Email Controls", the second is "Item Controls". Each check box has its own individual name.
In the first group there will always be at least 5 controls - Email_D through Email_H. There may be additional controls. This code snippet shows one extra called Email_I. The line "On Error GoTo No_More_Email_Controls" works correctly when it hits the non-existent Email_I control.
So far, so good.
The second group will always have Email_6 through Email_10. The code shows two possible extras: Email_11 and Email_12. When the interpreter hits the test line for Email_11 it generates error 438 and pops up a message box - which tells me that the line "On Error GoTo No_More_Item_Controls" either isn't working, or is being ignored. I've tried a dozen different fixes from around the 'net, but it refuses to handle the error.
I have noticed that if I get rid of the first error handler (and the code that would generate it) the second error handler works fine. I tried setting the error handler to "GoTo 0" right before I set the second error handler, but that didn't help. What step am I missing?
----- Code -----
With Worksheets(strSheet)
bField = False 'Set default flag state
On Error GoTo No_More_Email_Controls 'When no more controls, break out
'If any of the attachment types has been selected, set flag
If .Email_D.Value = True Or _
.Email_E.Value = True Or _
.Email_F.Value = True Or _
.Email_G.Value = True Or _
.Email_H.Value = True Then
bField = True
ElseIf .Email_I.Value = True Then
bField = True
End If
No_More_Email_Controls:
bEmail = False 'Set default flag state
On Error GoTo No_More_Item_Controls 'When no more controls, break out
'If any equipment has been selected, set flag to True
'(There will always be at least up to #35 controls, unless you delete them - don't.)
If .Email_6.Value = True Or _
.Email_7.Value = True Or _
.Email_8.Value = True Or _
.Email_9.Value = True Or _
.Email_10.Value = True Or _
bEmail = True
ElseIf .Email_11.Value = True Then
bEmail = True
ElseIf .Email_12.Value = True Then
bEmail = True
End If
No_More_Item_Controls:
'If no error or ran out of controls...
If Err.Number = 0 Or Err.Number = 438 Then
<snip>
End If
End With
Bookmarks