Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Checking to see if a button is selected


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

  #2   Report Post  
Posted to microsoft.public.excel.programming
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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Checking to see if a button is selected


Thanks for answering, Dave!

Well, I want to generate an error message telling the user that the
must select one of those buttons. As far as I can tell, I have to hav
a Validation object to do that.

Am I wrong? Certainly the giant IF statement is the easiest.

Thanks again

--
cheaperThanAPr
-----------------------------------------------------------------------
cheaperThanAPro's Profile: http://www.excelforum.com/member.php...fo&userid=2824
View this thread: http://www.excelforum.com/showthread.php?threadid=47824

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Checking to see if a button is selected

I'm not sure what you mean by a validation object.

I assumed that you had a userform (created in the VBE--not a worksheet made to
get user input).

If that's correct, you could do something on the "Ok/continue" button on the
userform.

That giant if statement (or the loop).

if me.optionbutton1.value = true _
or me.optionbutton2.value = true _
or me.optionbutton3.value = true then
'keep going, one was selected
'put a label on the userform and make sure it's clear
me.label1.caption = ""
else
'msgbox "Please select one of those options"
'or put it in the label
me.label1.caption = "Please select one of those options"
exit sub
end if

'continue your code.



cheaperThanAPro wrote:

Thanks for answering, Dave!

Well, I want to generate an error message telling the user that they
must select one of those buttons. As far as I can tell, I have to have
a Validation object to do that.

Am I wrong? Certainly the giant IF statement is the easiest.

Thanks again!

--
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
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Checking to see if a button is selected


It's just something I read in the online help for Excel. I guess
didn't understand it very well.

The important thing is that you solved my problem! It work
beautifully. Thanks so much!

cta

--
cheaperThanAPr
-----------------------------------------------------------------------
cheaperThanAPro's Profile: http://www.excelforum.com/member.php...fo&userid=2824
View this thread: http://www.excelforum.com/showthread.php?threadid=47824

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I lock a radio button group if a N/A button is selected worry a lot Excel Discussion (Misc queries) 2 May 21st 05 08:33 PM
Determine which button was selected ?? dcarr Excel Programming 4 October 27th 04 11:02 PM
Macro to run in same row as selected button nejl Excel Programming 2 September 6th 04 02:17 PM
Activate button when row selected. Johnnyb Excel Programming 3 August 17th 04 01:51 PM
Checking to see if user selected an Option Kirk[_2_] Excel Programming 1 August 27th 03 09:46 PM


All times are GMT +1. The time now is 07:15 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"