PDA

View Full Version : Solved: Msgbox if value not found



Viko
01-24-2010, 02:45 PM
Can anybody please help me with a code that will search true CheckBoxes
from 1 true 10 in a userform and if it finds that they are all empty to return msgbox warning?

Bob Phillips
01-24-2010, 04:12 PM
fClear = True
For i = 1 To 10

If Me.Controls("CheckBox" & i").Value Then

fClear = False
Exit For
End If
Next i

If fClear Then MsgBox "All Checkboxes unchecked"

mikerickson
01-25-2010, 01:48 AM
This is one of the legitimate uses of GoTo

For i = 1 To 10
If Me.Controls("CheckBox" & i).Value Then GoTo Skip
Next i

MsgBox "all false"

Skip:
Rem rest of routine

Viko
01-26-2010, 01:29 PM
Thanks guys!

I used the code that xld provided as It does exactly what I needed!

Thank you very much!

Viko
01-26-2010, 01:32 PM
Dim ChkBox As MSForms.CheckBox
Dim I As Integer
fClear = True
For I = 1 To 10
Set ChkBox = Me.Controls("CheckBox" & I)
If ChkBox.Enabled = True And ChkBox.Value = True Then
fClear = False
Exit For
End If
Next I

f fClear Then MsgBox"Test"


I change it to this and I think the added lines are important in order the code to run smoothly


Cheers!

Bob Phillips
01-26-2010, 03:05 PM
You can do it without the Set



fClear = True
For i = 1 To 10

With Me.Controls("CheckBox" & i")

IF .Enabled And .Value Then

fClear = False
Exit For
End If
End With
Next i

If fClear Then MsgBox "All Checkboxes unchecked"