Conditional Expression For Radio Button

legalhustler

Well-known Member
Joined
Jun 5, 2014
Messages
1,171
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

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Case 1
Me![Text101] = "Y"
Me.Frame112.Locked = False

If I use this code for Case 1, although it allows me to select any of the three radio buttons in my Form for "SBE" (or Frame112) and I pick one of the three options, when I save the record, it does not show either "Yes", or "No" or "TBD" in my Table. It just shows blank for the SBE field for that record even though I made a selection in my Form for Frame112.
 
Last edited:
Upvote 0
No, I did try it and I understand the problem. Did you understand my reply?
You have at least two errors in your code that you need to correct. Did you try to do that?

One thing that is important to understand, your table fields "CBE" and "SBE" are NOT bound to your radio buttons, they are bound to Text101 and Text111. So they are determined by your VBA code, not necessarily your radio button selection. If your VBA code is not written correctly, your Table values will not reflect your radio button selections. It is important to understand the flow of how it all works. If you "walk-the-chain" logically, you should be able to figure what it is doing and why.
 
Upvote 0
No, I did try it and I understand the problem. Did you understand my reply?
You have at least two errors in your code that you need to correct. Did you try to do that?

One thing that is important to understand, your table fields "CBE" and "SBE" are NOT bound to your radio buttons, they are bound to Text101 and Text111. So they are determined by your VBA code, not necessarily your radio button selection. If your VBA code is not written correctly, your Table values will not reflect your radio button selections. It is important to understand the flow of how it all works. If you "walk-the-chain" logically, you should be able to figure what it is doing and why.

Let's just forcus on Frame103 Case 1 code. I tried it as mentioned in my post #52 but the SBE field in my Table for the record shows a blank even though I had selected for example "No" for "SBE" in my Form. I understand it is bounded to Text101 and Text111, but why did you leave it empty in your code? Because it's now showing a blank for the SBE field in my Table. Again, how can I show "Yes" and "No" and "TBD" in my Table when one of them is selected in my Form?

Here is my updated code for your reference:
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
            Me![Text111] = "N"
        Case 3
            Me![Text101] = "TBD"
            Me.Frame112 = 3
            Me.Frame112.Locked = True
            Me![Text111] = "TBD"
                                
End Select
End Sub
 
Last edited:
Upvote 0
OK, Frame103 is dealing with the "CBE" field, right?
So when a "Y" is selected in this frame for CBE, you said that you want options "Y","N", and "TBD" to all be available to be selected in Frame112 for SBE, right?
So, at this point, you want all those options to be available, but nothing should be selected for SBE at this point, should it (since it can be any of those three options)?
If that is the case, you do NOT want to update Text111 at this point. You want to wait until they have made the selection in the SBE box (Frame112) before updating Text111.
Or is this not how you want it to work?
 
Upvote 0

OK, Frame103 is dealing with the "CBE" field, right?

Correct

So when a "Y" is selected in this frame for CBE, you said that you want options "Y","N", and "TBD" to all be available to be selected in Frame112 for SBE, right?

Correct

So, at this point, you want all those options to be available, but nothing should be selected for SBE at this point, should it (since it can be any of those three options)?

Correct - all three options should be available but nothing should be selected for SBE (Frame112).


If that is the case, you do NOT want to update Text111 at this point. You want to wait until they have made the selection in the SBE box (Frame112) before updating Text111.
Or is this not how you want it to work?

Correct - when they make a selection in the SBE box (Frame112) it should show the correct data (Yes, No, TBD) in it's respective field in the Table. And what I've been trying to say is that even though I make a selection in the SBE box and save the record, it does not show in the Table, it just shows a blank, using the last code I provided you. This is what my problem is.
 
Last edited:
Upvote 0
even though I make a selection in the SBE box and save the record, it does not show in the Table, it just shows a blank, using the last code I provided you. This is what my problem is.
Note that when you make your selection in the SBE Option Box, you are now dealing with Frame112, not Frame103 anymore (that is linked to CBE). So, when you make your selection in the SBE Option Box, it is the VBA code in Frame112 that should be setting the value of Text111. So what does that code currently look like (the Frame112_AfterUpdate code)? Does it still look like the code shown in post #43? If not, post it here (I don't have your database in front on me, its own my home computer, so I cannot see all that code).

Also, if the code in post #43 is what your currently have, is it your intention that when "Y" is selected for SBE, that you want Text101 (which is for "CBE") to be set to "TBD"? That seems a little odd.

If all this appears to be correct, we probably need to check for other VBA code that may be coming into play here (maybe VBA code attached to events on Text101 and Text111). I will need to inspect that when I am home tonight and see if there is any interference from other VBA code.
 
Upvote 0
Note that when you make your selection in the SBE Option Box, you are now dealing with Frame112, not Frame103 anymore (that is linked to CBE). So, when you make your selection in the SBE Option Box, it is the VBA code in Frame112 that should be setting the value of Text111. So what does that code currently look like (the Frame112_AfterUpdate code)? Does it still look like the code shown in post #43? If not, post it here (I don't have your database in front on me, its own my home computer, so I cannot see all that code).

Also, if the code in post #43 is what your currently have, is it your intention that when "Y" is selected for SBE, that you want Text101 (which is for "CBE") to be set to "TBD"? That seems a little odd.

If all this appears to be correct, we probably need to check for other VBA code that may be coming into play here (maybe VBA code attached to events on Text101 and Text111). I will need to inspect that when I am home tonight and see if there is any interference from other VBA code.


I deleted the enitre code in post #43 in my VBA. I just want to focus on Frame103 because it is the trigger that determines what should be selected in Frame112. I don't have any code for Frame112_AfterUpdate any more. I only have the following, which is for Frame103:

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
            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 deleted the enitre code in post #43 in my <acronym title="visual basic for applications" style="border-width: 0px 0px 1px; border-bottom-style: dotted; border-bottom-color: rgb(0, 0, 0); cursor: help; color: rgb(51, 51, 51); background-color: rgb(250, 250, 250);">VBA</acronym>. I just want to focus on Frame103 because it is the trigger that determines what should be selected in Frame112. I don't have any code for Frame112_AfterUpdate any more. I only have the following, which is for Frame103:
Then how will Text111 ever get updated???
Even if you set it initially when Frame103 is updated, it will never change with any entries made to Frame112.

Do you understand how this code works? The Frame103_AfterUpdate event ONLY runs after a selection is made in Frame103 (which is your CBE box). It does NOT run when a change is made in Frame112 (SBE).
If you have no code for Frame112_AfterUpdate, making changes in your SBE box will do absolutely nothing to your back-end table.
 
Upvote 0
Then how will Text111 ever get updated???
Even if you set it initially when Frame103 is updated, it will never change with any entries made to Frame112.

Do you understand how this code works? The Frame103_AfterUpdate event ONLY runs after a selection is made in Frame103 (which is your CBE box). It does NOT run when a change is made in Frame112 (SBE).
If you have no code for Frame112_AfterUpdate, making changes in your SBE box will do absolutely nothing to your back-end table.

I see what you're saying - Text111 does get updated in Case 2 and Case 3 for Frame103 (CBE) but nothing gets updated in my back-end table for Case 1. In summary, if the user clicks in Frame103 first then the following needs to happen:

1) If "Yes" is selected in Frame103 (CBE), then all three options should be available for selection in Frame112 (SBE) and updated properly in the back-end table.
2) If "No" is selected in Frame103 (CBE), then "No" should be automatically selected in Frame112 (SBE) and lock the remaining two options from selecting and updating properly in the back-end table.
3) If "TBD" is selected in Frame103 (CBE), then "TBD" should be automatically selected in Frame112 (SBE) and lock the remaining two options from selecting and updating properly in the back-end table.

If the user does not make a selection on Frame103 (CBE) first but starts with Frame112 (SBE) then we just need the code we created for the above to be reversed (which I have done below).

So here is what I have so far:

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
            Me![Text111] = "N"
        Case 3
            Me![Text101] = "TBD"
            Me.Frame112 = 3
            Me.Frame112.Locked = True
            Me![Text111] = "TBD"
                                
End Select
End Sub
Private Sub Frame112_AfterUpdate()
    Select Case Me![Frame112]
        Case 1
            Me![Text111] = "Y"
            Me.Frame103.Locked = False
           
        Case 2
            Me![Text111] = "N"
            Me.Frame103 = 2
            Me.Frame103.Locked = True
            Me![Text101] = "N"
        Case 3
            Me![Text101] = "TBD"
            Me.Frame103 = 3
            Me.Frame103.Locked = True
            Me![Text101] = "TBD"
                                
End Select
End Sub

I need help revising the code because when I select "Yes" for CBE then click "No" for SBE, then the "Yes" for CBE changes to "No" automatically to correspond with "No" for SBE. If I select "Yes" for CBE I should be able to select any of the three option for SBE without my answer for CBE changing.

Thanks.
 
Upvote 0

Forum statistics

Threads
1,215,352
Messages
6,124,457
Members
449,161
Latest member
NHOJ

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