Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
verify state of option button
I have a group of four option buttons on a userform. The user is
required to check select one of them. What can I put in my code to verify this. What I currently have is below but it does not seem like it is the most efficient way of completing this task as I have this occurrence 34 separate times. sub verify() If opt1.Value = False And opt2.Value = False And opt3.Value = False And opt4.Value = False Then GoTo 2: ElseIf opt5.Value = False And opt6.Value = False And opt7.Value = False And opt8.Value = False Then GoTo 2 end if 'other code below .... exit sub 2: msgbox "Please verify that you have completed each section" end sub |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
verify state of option button
try this
Sub verify() Select Case True Case Me.OptionButton1.Value 'code here Case Me.OptionButton2.Value 'code here Case Me.OptionButton3.Value 'code here Case Me.OptionButton4.Value 'code here Case Else 'code here End Select End Sub "stewart" wrote: I have a group of four option buttons on a userform. The user is required to check select one of them. What can I put in my code to verify this. What I currently have is below but it does not seem like it is the most efficient way of completing this task as I have this occurrence 34 separate times. sub verify() If opt1.Value = False And opt2.Value = False And opt3.Value = False And opt4.Value = False Then GoTo 2: ElseIf opt5.Value = False And opt6.Value = False And opt7.Value = False And opt8.Value = False Then GoTo 2 end if 'other code below .... exit sub 2: msgbox "Please verify that you have completed each section" end sub |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
verify state of option button
there's another way somebody told me, once......
using frames to group each set of option buttons, you only have to check if the # of frames with a true value are the same as the # of frames on your userform! if 24 frames = true equals 24 frames total, then you know one button (and only one) was selected in each frame. this is the code i came up with from merjet............. it is JUST the looping thru the frames to see if # matches. this is in my userform code. ========================= Sub cmdEnter_click() '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 ======================= hope it helps! susan "stewart" wrote in message oups.com... I have a group of four option buttons on a userform. The user is required to check select one of them. What can I put in my code to verify this. What I currently have is below but it does not seem like it is the most efficient way of completing this task as I have this occurrence 34 separate times. sub verify() If opt1.Value = False And opt2.Value = False And opt3.Value = False And opt4.Value = False Then GoTo 2: ElseIf opt5.Value = False And opt6.Value = False And opt7.Value = False And opt8.Value = False Then GoTo 2 end if 'other code below ... exit sub 2: msgbox "Please verify that you have completed each section" end sub |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
verify state of option button
A couple of possible approaches:
If opt1 + opt2 + opt3 + opt4 Then Msgbox "Something selected" Else ' All are False (or Null) Msgbox "Nothing selected" End If OR Select Case True Case opt1, opt2, opt3, opt4 ' One of the above is True Msgbox "Something selected" Case Else ' All are False (or Null) Msgbox "Nothing selected" End Select I like the 2nd appoach cause 1) its easier to read IMO, 2) easier to add additional buttons 3) easier to break a button off to a seperate Case statement. In my mind, it mimics the functionality of an Option group (available with Access or vb control sets, etc.) fairly well. If you are working on a UserForm (which has a Controls collection), you could also do something like: Dim i As Integer Dim iSelected As Integer For i = 1 To 4 If Controls("Opt" & i) Then iSelected = i Exit For End If Next i If iSelected = 0 Then MsgBox "None selected" End If HTH, "stewart" wrote in message oups.com... I have a group of four option buttons on a userform. The user is required to check select one of them. What can I put in my code to verify this. What I currently have is below but it does not seem like it is the most efficient way of completing this task as I have this occurrence 34 separate times. sub verify() If opt1.Value = False And opt2.Value = False And opt3.Value = False And opt4.Value = False Then GoTo 2: ElseIf opt5.Value = False And opt6.Value = False And opt7.Value = False And opt8.Value = False Then GoTo 2 end if 'other code below ... exit sub 2: msgbox "Please verify that you have completed each section" end sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
need help on how to grey out one option button in one group box based on the selection of another option button in another group box | Excel Programming | |||
Triple state command button | Excel Programming | |||
Mouse-Over State on Graphic Button | Excel Programming | |||
triple state option buttons | Excel Programming | |||
state of option button | Excel Programming |