methuselah
methuselah

Reputation: 13216

Validating checkboxes using VBA

I'm having difficulty validating a group of radio buttons, this is the code I'm using right now but I keep getting the error message: Runtime error 438 - Object doesn't support this property or method.

This is the code that is causing the problem.

For Each ctl In Me.frPriority.Controls
        If ctl.Value = True Then GoTo nxtCheck1
    Next
        MsgBox "You didn't select a priority"
    Exit Sub
nxtCheck1:

The line causing all the trouble is

If ctl.Value = True Then

How can I resole this problem?

Upvotes: 0

Views: 1526

Answers (2)

John Bustos
John Bustos

Reputation: 19574

You problem is that you're looping through all the controls and some of your controls won't have a Value property.

try something like this:

For Each ctl In Me.frPriority.Controls
   If TypeOf ctl Is msforms.OptionButton Then
        If ctl.Value = True Then GoTo nxtCheck1
   End if
Next

Upvotes: 1

nutsch
nutsch

Reputation: 5962

If you have non-option buttons control types in your frame, use this, checking for the control type first.

For Each ctl In Me.frPriority.Controls
    If TypeOf ctl Is msforms.OptionButton Then
        If ctl.Value = True Then GoTo nxtCheck1
    end if 
Next
        MsgBox "You didn't select a priority"
    Exit Sub
nxtCheck1:

Upvotes: 3

Related Questions