PC Review


Reply
Thread Tools Rate Thread

code to check OptionButton selected within multiple frames

 
 
porky2j@hotmail.com
Guest
Posts: n/a
 
      16th Jul 2008
Hi Guys,

I am a total newbie to this and the group has been really helpful in
learning so far!

I am setting up a UserForm that has multiple frames containing
different OptionButtons.

When the OK button is clicked I want it to be coded to check that each
frame has an OptionButton Selected. Is it possible to write this code
referring to the frame (i.e. group of OptionButtons) or do I have to
write the code including each individual OptionButton like below:

If Me.OptionButton1.Value = False And Me.OptionButton2.Value = False
And _
Me.OptionButton3.Value = False And Me.OptionButton4.Value = False
Then
MsgBox " you must select a squad ", vbExclamation, "Input
Error"
Exit Sub
End If

I have 20 option buttons in one frame so just wondering if there is a
shorter way to write the code?

Thanks in advance
Paul
 
Reply With Quote
 
 
 
 
Susan
Guest
Posts: n/a
 
      16th Jul 2008
this is coding that someone helped me develop to do the same thing -
loop through all the frames & check that there's one option button
selected in each frame. in this case there were 12 frames:
===================================
Sub cmdEnter_click()

Dim oControl as Control

'make sure an option button is checked in each frame
i = 0

For Each oControl In Me.Controls
If TypeOf oControl Is msforms.OptionButton Then
If oControl Then
i = i + 1
End If
End If
Next
If i >= 12 Then 'no. of frames
'do nothing
Else
MsgBox "Every frame must have a selected option button!" _
& vbCrLf & _
vbCrLf & _
"Please go back and answer all the questions." _
, vbOKOnly + vbExclamation
Exit Sub
End If
End Sub
============================
hope it gets you started.

susan



On Jul 16, 5:55*am, pork...@hotmail.com wrote:
> Hi Guys,
>
> I am a total newbie to this and the group has been really helpful in
> learning so far!
>
> I am setting up a UserForm that has multiple frames containing
> different OptionButtons.
>
> When the OK button is clicked I want it to be coded to check that each
> frame has an OptionButton Selected. Is it possible to write this code
> referring to the frame (i.e. group of OptionButtons) or do I have to
> write the code including each individual OptionButton like below:
>
> If Me.OptionButton1.Value = False And Me.OptionButton2.Value = False
> And _
> * * Me.OptionButton3.Value = False And Me.OptionButton4.Value = False
> Then
> * * * * MsgBox " you must select a squad ", vbExclamation, "Input
> Error"
> * * * * Exit Sub
> * * End If
>
> I have 20 option buttons in one frame so just wondering if there is a
> shorter way to write the code?
>
> Thanks in advance
> Paul


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Output from Frames - multiple optionbutton groups Monkeeman Microsoft Excel Programming 1 5th Aug 2011 08:22 PM
Check if a optionbutton is selected Gert-Jan Microsoft Excel Programming 9 22nd Dec 2006 06:47 AM
Use optionbutton value to select code to run. Casey Microsoft Excel Programming 5 10th May 2006 11:00 PM
How do I write code to create multiple hyperlinks on a Frames page =?Utf-8?B?QmVqZXdlbGw=?= Microsoft Frontpage 3 14th Jan 2006 01:10 PM
Execute some code with check box selected Rui Soares via AccessMonster.com Microsoft Access Form Coding 1 16th Oct 2005 05:35 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:16 PM.