Conditional Expression For Radio Button

legalhustler

Well-known Member
Joined
Jun 5, 2014
Messages
1,165
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:
My previous post was more about post #16 (I hadn't seen post #17 when I posted it). The unnecessary redundancy in the code is what caught my eye there, so that is what I was focusing on before moving forward (making sure we get the initial stuff straight before going to new stuff).


OK, now we are getting in to some fun stuff! So basically, you want to Disable the "No" option in Frame112 if they select "Yes" or "TBD" in Frame103. So, first thing is go into Design View, and click on the "No" radio button in Frame112 to see what it is named. If you haven't changed it, then the name will start with "Option". So it might be something like Option16.

So, in our code under both Case 1 and Case 3, you will want to add the following line:
Code:
Me.Option16.Enabled = False
You will probably also want to add code to Case 2 that says:
Code:
Me.Option16.Enabled = True
if you want "No" re-enabled again if they select "No" in Frame103.

Thank you so much. One last thing:

When I select "No" in Frame103 it automatically selects "No" in Frame112 (which is perfect), but when I re-select "Yes" or "TBD" in Frame103 it's still locked on "No" in Frame112. How do I re-enable all three options in Frame112 if I reselect "Yes" or "TBD"?


Thank you in advance.
 
Upvote 0

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Can you post your code, as you currently have it?
I know numerous changes have been made it to through the course of this thread, so I just want to make sure that my answer is in-line with what you currently have.
 
Upvote 0
Can you post your code, as you currently have it?
I know numerous changes have been made it to through the course of this thread, so I just want to make sure that my answer is in-line with what you currently have.

The other scenario that disables the "No" was for another OptionGroup but I just happened to use the same example to keep it from confusing. Below is the original code that locks "No" in Frame112 when "No" is selected in Frame103. So when I try to re-select "Yes" or "TBD" in Frame103 it is still locked on "No" in Frame112.

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
Basically, if you have one options that "locks" something, and you want to unlock it if other options are picked, you will want to add that line that locks/unlocks the option under each different option they may select. So we need to add "Me.Frame112.Locked = False" under the other two options, i.e.
Code:
Private Sub Frame103_AfterUpdate()
    
    Select Case Me![Frame103]
    
        Case 1
            Me![Text101] = "Y"
            Me.Frame112.Locked = False
                       
        Case 2
            Me![Text101] = "N"
            Me.Frame112 = 2
            Me.Frame112.Locked = True
            
        Case 3
            Me![Text101] = "TBD"
            Me.Frame112.Locked = False                                
    
    End Select
        
End Sub
This was also discussed a bit in posts 4 and 12 (hopefully, you are beginning to understand the pattern here).
 
Last edited:
Upvote 0
Basically, if you have one options that "locks" something, and you want to unlock it if other options are picked, you will want to add that line that locks/unlocks the option under each different option they may select. So we need to add "Me.Frame112.Locked = False" under the other two options, i.e.
Code:
Private Sub Frame103_AfterUpdate()
    
    Select Case Me![Frame103]
    
        Case 1
            Me![Text101] = "Y"
            Me.Frame112.Locked = False
                       
        Case 2
            Me![Text101] = "N"
            Me.Frame112 = 2
            Me.Frame112.Locked = True
            
        Case 3
            Me![Text101] = "TBD"
            Me.Frame112.Locked = False                                
    
    End Select
        
End Sub
This was also discussed a bit in posts 4 and 12 (hopefully, you are beginning to understand the pattern here).

Yeah, I thought I did that and set it to False, but I think accidently also copied Me.Frame112 = 2, which specifies the "No" portion instead of just setting the whole Frame to unlocked. I learned alot from your examples. Do you recommend any other sites or Youtube videos on VBA coding for beginners?

Thank you again for all your help.

Thread closed....for now ;)
 
Upvote 0
To tell you the truth, I get a lot of information just by Googling the topic at hand, i.e. Googling "access vba disable form control". The more precise the topic you type in, the more likely you are to find what you need.

However, there are tutorials out there. You might want to try Googling "Access Form Design" and see what pops up.
The DataPigTechnologies website has a myriad of good Access tutorial videos too (DataPig Technologies Access Videos).

Hope that helps!
 
Upvote 0
Basically, if you have one options that "locks" something, and you want to unlock it if other options are picked, you will want to add that line that locks/unlocks the option under each different option they may select. So we need to add "Me.Frame112.Locked = False" under the other two options, i.e.
Code:
Private Sub Frame103_AfterUpdate()
    
    Select Case Me![Frame103]
    
        Case 1
            Me![Text101] = "Y"
            Me.Frame112.Locked = False
                       
        Case 2
            Me![Text101] = "N"
            Me.Frame112 = 2
            Me.Frame112.Locked = True
            
        Case 3
            Me![Text101] = "TBD"
            Me.Frame112.Locked = False                                
    
    End Select
        
End Sub
This was also discussed a bit in posts 4 and 12 (hopefully, you are beginning to understand the pattern here).

I found another issue with Case 1 for Frame103 (see below). When I select the "Yes" radio button in Frame103 it allows me to select "Yes" "No" and "TBD" in Frame112 (this is fine), HOWEVER "Yes" and "No" does not show in my Table only "TBD." I believe you mentioned the code only picks the last option, which in this case is Me![Text111] = "TBD". How can I make the code show all three options in my Table when Frame112 is selected, instead of just "TBD"?

Also, since this is a data entry form, when I navigate at the bottom to a new/blank form, the radio buttons are not cleared. This means that none of my radio buttons should be selected when I enter new data to the form. Can you please help.

TIA!

Code:
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
End Sub


Private Sub Frame103_AfterUpdate()
    Select Case Me![Frame103]
        Case 1
            Me![Text101] = "Y"
            Me.Frame112.Locked = False
            Me![Text111] = "Y"
            Me![Text111] = "N"
            Me![Text111] = "TBD"
           
                    
        Case 2
            Me![Text101] = "N"
            Me.Frame112 = 2
            Me.Frame112.Locked = True
            Me![Text111] = "N"
            
        Case 3
            Me![Text101] = "TBD"
            Me.Frame112 = 3
            Me.Frame112.Locked = True
            Me![Text111] = "TBD"
                                
End Select
End Sub
 
Upvote 0
I am just getting back from a short vacation and getting caught up on email and work now.
Let me know if you still have questions on this, and I will look at it when I get a chance (hopefully tonight).
 
Upvote 0
I am just getting back from a short vacation and getting caught up on email and work now.
Let me know if you still have questions on this, and I will look at it when I get a chance (hopefully tonight).


Yes - I still have this issue pending. Thanks!
 
Upvote 0
OK, let's back up again, because I see it appears you still aren't quite clear how this code all works. Since it all builds on itself, if you do not understand the base layer, building on top of that is only going to make things more confusing. It is important to understand how the code works before building on top of it.

So, there is a problem with the logic of this block of code that your wrote:
Code:
Select Case Me![Frame103] 
    Case 1 
        Me![Text101] = "Y" 
        Me.Frame112.Locked = False 
        Me![Text111] = "Y" 
        Me![Text111] = "N" 
        Me![Text111] = "<acronym title="To be discussed" style="border-width: 0px 0px 1px; border-bottom-style: dotted; border-bottom-color: rgb(0, 0, 0); cursor: help;">TBD</acronym>"

What this says, is if that the first option is selected in Frame103, then set the following fields equal to the values that you specify. Hence, each item you have listed under there should only be listed once. If option 1 is selected for Frame103, what do you want to set Text111 to? It will only be one of "Y", "N", or "TBD", not all three. So you only should have one of those lines listed there, not all three.

It might make more sense if I use we look at a similar no-technical example of this structure. Maybe something like this:
Code:
Select Case "We are having a baby"
    Case "The baby is a boy"
        Set BabyName = "Karl"
        Set BabyName = "Bob"
        Set BabyName = "Mark"
That doesn't make much sense. You are only going to give the baby one name, not all three. So you only want to list the BabyName that you want.
If you did use this structure it would do something -- the last setting wins. So the BabyName would be "Mark". Hence the other two lines are unnecessary and don't really do anything. Hence they should not be there.

So, back to your code, under each "Case" block, no field/property combination should be listed more than once.

Does that help clarify things?
So, how would you rewrite that block of code you have?
 
Upvote 0

Forum statistics

Threads
1,214,631
Messages
6,120,645
Members
448,974
Latest member
DumbFinanceBro

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