View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Checking to see if a button is selected

How about just a giant Or statement:

if me.optionbutton1.value = true _
or me.optionbutton2.value = true _
or ....

===
Or loop through the controls in that frame looking for optionbuttons that are
chosen.

Option Explicit
Private Sub CommandButton1_Click()
Dim myCtrl As Control
Dim AtLeastOneChosen As Boolean

AtLeastOneChosen = False
For Each myCtrl In Me.Frame1.Controls
If TypeOf myCtrl Is MSForms.OptionButton Then
If myCtrl.Object.Value = True Then
AtLeastOneChosen = True
Exit For
End If
End If
Next myCtrl

MsgBox AtLeastOneChosen
End Sub



cheaperThanAPro wrote:

Sorry to pester so much, but I keep running against walls with this
form!

I have a series of option buttons in a frame box. They seem to work
correctly (thanks to some help I got here). What I need is to make
sure the user has selected one of them before the form moves on to the
next record.

I've got a Validation object set up--at least, I *think* I do. It's
xlValidateCustom, and I'm trying to set up a formula for it. According
to the documentation, I need to set up something that evaluates to True,
and from my attempts it looks like I can't use something with an equals
sign in it. The one reliable test for whether the button has been
clicked is whether there is text in a particular cell, so I tried
"IsEmpty(ActiveCell)=False," but the compiler didn't like that. There
seems no comparable expression I can find in the documentation that
would evaluate to True when there is text in the cell.

Of course, there may be some other way of going about this that would
be much simpler. Currently I have all the buttons set up in an
If-ElseIf sequence, and the check comes just before the End, being an
Else rather than an ElseIf.

Any help would be appreciated! Thanks!

--
cheaperThanAPro
------------------------------------------------------------------------
cheaperThanAPro's Profile: http://www.excelforum.com/member.php...o&userid=28241
View this thread: http://www.excelforum.com/showthread...hreadid=478243


--

Dave Peterson