Conditional Expression For Radio Button

legalhustler

Well-known Member
Joined
Jun 5, 2014
Messages
1,160
Office Version
  1. 365
Platform
  1. Windows
I have two controls in my form and each has a radio button. In control 1 the user selects "No", then I want control 2 to automatically select "No" for the radio button. If the user selects "Yes" in control 1 then I want control 2 to do nothing and have the user the option to pick "Yes" or "No"

Will I have to build IIF statement in control 2 in the Validation Rule property? Or something in the Event properties?
 
Last edited:

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
What exactly do you have?
Do you have two Option Groups, each with two radio buttons (one for "Yes", and one for "No")?

Typically, what I have seen done most often is have VBA code in the AfterUpdate event of your first Option Group where if certain conditions are met, makes the selection in your second Option Group.
 
Upvote 0
What exactly do you have?
Do you have two Option Groups, each with two radio buttons (one for "Yes", and one for "No")?

Typically, what I have seen done most often is have VBA code in the AfterUpdate event of your first Option Group where if certain conditions are met, makes the selection in your second Option Group.

I have three option groups but I want to do this done for only two. Both groups has one "Yes", "No" and "TBD".

VBA would be nice if the user selected "No" in control 1 button then it should automatically select "No" in control 2. If possible, would like to see a VBA code so user cannot select any other options in control 2 and a VBA code where "No" is selected in control 2 but user also has the option to pick another selection.

Thank you so much in helping me with all my questions. Wish you were working in my office.:)
 
Upvote 0
Sorry, I have been away this weekend and am just getting back here.

Let's set up an example. You can add your option groups using the Option Group Wizard. Access likes to use "FrameX" as the name of the Option Groups (not my choice, but we'll roll with it).

So, let's say we set up two Option Groups, "Frame0" and "Frame1". And each has three options, "Yes", "No", and "TBD", which will have values of 1,2,and 3 respectively. So, if we can add the following VBA code to the "After Update" event of Frame0 that if its value is set to "No", it will set Frame1's value to No also and Lock it. That code would look like this:
Code:
Private Sub Frame0_AfterUpdate()


    'If first option group equals no, set second one equal to no
    If Me.Frame0 = 2 Then
        Me.Frame1 = 2
        Me.Frame1.Locked = True
    End If
    
End Sub
You might want to add and "Else" clause to this if, so if a person first picks "No", but then changes it to "Yes", it unlocks Frame1 so that they can change that., i.e.
Code:
Private Sub Frame0_AfterUpdate()


    'If first option group equals no, set second one equal to no
    If Me.Frame0 = 2 Then
        Me.Frame1 = 2
        Me.Frame1.Locked = True
    Else
        Me.Frame1.Locked = False
    End If
    
End Sub
 
Upvote 0
Sorry, I have been away this weekend and am just getting back here.

Let's set up an example. You can add your option groups using the Option Group Wizard. Access likes to use "FrameX" as the name of the Option Groups (not my choice, but we'll roll with it).

So, let's say we set up two Option Groups, "Frame0" and "Frame1". And each has three options, "Yes", "No", and "TBD", which will have values of 1,2,and 3 respectively. So, if we can add the following VBA code to the "After Update" event of Frame0 that if its value is set to "No", it will set Frame1's value to No also and Lock it. That code would look like this:
Code:
Private Sub Frame0_AfterUpdate()


    'If first option group equals no, set second one equal to no
    If Me.Frame0 = 2 Then
        Me.Frame1 = 2
        Me.Frame1.Locked = True
    End If
    
End Sub

I get the following error message: Ambigious name detected: Frame_103AfterUpdate.

Keep in mind that my Option Groups (Frame103 and Frame112) already has other AfterUpdateEvent macros that converts the values of "Yes", "No", "TBD", from 1,2,3 to "Y","N", and "TBD" respectively in my source Table. See below:

Code:
Private Sub Frame103_AfterUpdate()
Select Case Me![Frame103]
    Case 1
        Me![Text101] = "Y"
    Case 2
        Me![Text101] = "N"
    Case 3
        Me![Text101] = "TBD"
End Select
End Sub



Private Sub Frame112_AfterUpdate()
Select Case Me![Frame112]
    Case 1
        Me![Text111] = "Y"
    Case 2
        Me![Text111] = "N"
    Case 3
        Me![Text111] = "TBD"
End Select
End Sub

Do I need to reference Text101 and Text111 in your code?
 
Last edited:
Upvote 0
I get the following error message: Ambigious name detected: Frame_103AfterUpdate
You cannot have two different Event procedures in the same module with the same name.
If you already have a "Frame103_AfterUpdate" event procedure, you will need to combine all your code into a single procedures.
 
Upvote 0
You cannot have two different Event procedures in the same module with the same name.
If you already have a "Frame103_AfterUpdate" event procedure, you will need to combine all your code into a single procedures.

I see. How would I do that? I tried removing End Sub from each code except the last one......
 
Upvote 0
It really depends on what the other code is doing. Sometimes there is an order of preference, or interaction you may need to worry about.
If you post the other Frame103_AfterUpdate VBA code, we could see what it is doing and have a better idea on how to combine the code.
 
Upvote 0
It really depends on what the other code is doing. Sometimes there is an order of preference, or interaction you may need to worry about.
If you post the other Frame103_AfterUpdate VBA code, we could see what it is doing and have a better idea on how to combine the code.

This is all the VBA code that I have under Frame103_AfterUpdate:

Note: Frame92 is another option group but your code should not apply to this frame..

Code:
Option Compare Database
Private Sub Frame103_AfterUpdate()
'If first option group equals no, set second one equal to no
    If Me.Frame103 = 2 Then
        Me.Frame112 = 2
        Me.Frame112.Locked = True

Private Sub Frame92_AfterUpdate()
Select Case Me![Frame92]
    Case 1
        Me![txtValues] = "Y"
    Case 2
        Me![txtValues] = "N"
    Case 3
        Me![txtValues] = "TBD"
End Select

Private Sub Frame103_AfterUpdate()
Select Case Me![Frame103]
    Case 1
        Me![Text101] = "Y"
    Case 2
        Me![Text101] = "N"
    Case 3
        Me![Text101] = "TBD"
End Select

Private Sub Frame112_AfterUpdate()
Select Case Me![Frame112]
    Case 1
        Me![Text111] = "Y"
    Case 2
        Me![Text111] = "N"
    Case 3
        Me![Text111] = "TBD"
End Select
End If
End Sub
 
Last edited:
Upvote 0
You are missing a bunch of "End Sub" statements. Note that you cannot next Subs inside of other Subs. You need to have an "End Sub" at the end of each Sub, before you start the next Sub.

I really am not sure what you are trying to do with [Text101]. I assume that it is some Text box outside of your Option Groups? In any event, you should be able to combine the two Frame103_AfterUpdate Event procedures like this:
Code:
Private Sub Frame103_AfterUpdate()


    Select Case Me![Frame103]
        Case 1
            Me![Text101] = "Y"
        Case 2
            Me![Text101] = "N"
            Me.Frame112 = 2
            Me.Frame112.Locked = True
        Case 3
            Me![Text101] = "TBD"
    End Select


End Sub
 
Upvote 0

Forum statistics

Threads
1,213,559
Messages
6,114,302
Members
448,564
Latest member
ED38

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top