Disable option group based on txt box result

Solola

Board Regular
Joined
Sep 23, 2003
Messages
73
I have a text box txtYesNo that is populated very simply via VBA code once the field appt_dte is updated:

Private Sub Appt_Dte_AfterUpdate()
If Me.appt_dte > Me.ConfCollDte Then
Me.txtYesNo = "yes"
Else
Me.txtYesNo = "no"
End If
End Sub

If the text box becomes "yes," I want the following option group frmChgRsn to be enabled. Otherwise, I want it disabled. I've entered the following code, but regardless of what txtYesNo says, it always appears enabled, and I can always select options in frmChgRsn.

Private Sub txtYesNo_AfterUpdate()
If Me.txtYesNo.Value = "yes" Then
frmChgRsn.Enabled = True
Else
frmChgRsn.Enabled = False
End If
End Sub

Is it possible I have my option group set up incorrectly? In the option group's properties, should it be set to enabled or disabled? Any idea on why this isn't working? Thanks!
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
I have tried your 'Private Sub txtYesNo_AfterUpdate()' code by creating a simple form creating a text box and naming it txtYesNo and then creating an option group called 'frmChgRsn'. If I type 'yes' into the textbox and hit enter, the option group becomes enabled and when I type no, the option group becomes disabled....so your code works for me, bud.:confused:
 
Upvote 0
The text box's After Update event is not fired if you "update" the textbox via code. To do what you're doing change the appt_dte's After Update event like this
Code:
Private Sub Appt_Dte_AfterUpdate()
If Me.appt_dte > Me.ConfCollDte Then
Me.txtYesNo = "yes"
Else
Me.txtYesNo = "no"
End If
call txtYesNo_AfterUpdate()
End Sub

hth,

Rich
 
Upvote 0
Thank you, revans! That worked.

(On a side note, using VBA to populate my txtYesNo was the result of one of my different attempts to fix the whole option group disabling problem. Initially, I just had my txtYesNo, and in its Control Source property, I had an iff formula assigning Yes or No based on the dates (same logic as the later vba code). txtYesNo updated appropriately, but the Option group still didn't disable/enable. With that sketchy description, any idea why that didn't work with the After Update event?)
 
Upvote 0
After Update only fires when the user changes data. When you "update" a control via code it does not fire. To use your iif scenario you'd have to attach the enable/disable to the change/update in the date control.

hth,

Rich
 
Upvote 0

Forum statistics

Threads
1,215,518
Messages
6,125,292
Members
449,218
Latest member
Excel Master

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