Undo not working in BeforeUpdate for Option Group

I have a pair of radiobuttons in an option group (values are 1 and 2).  Upon entry to the form, Option 2 is checked.  When the user clicks on option 1, I check for valid conditions and if I do not find them I want to undo the click and stop processing.

Here is the BeforeUpdate code:

Private Sub Which_Selection_BeforeUpdate(Cancel As Integer)
    If [condition] Then
        Cancel = 1
        Me.Which_Selection.Undo
        MsgBox "You cannot do that!"
        Exit Sub
    End If
End Sub

The BeforeUpdate gets executed.  The message appears, and processing stops at the exit sub.  BUT Option 1 stays clicked.

Why does the the option group not go back to having Option 2 clicked?
LVL 1
wsturdevAsked:
Who is Participating?
 
peter57rCommented:
Use the afterupdate event.

Private Sub Which_Selection_AfterUpdate()
    If [condition] Then
MsgBox "You cannot do that!"
             Me.Which_Selection=2
       
       
    End If
End Sub
0
 
peter57rCommented:
You shouldn't need the undo.

0
 
wsturdevAuthor Commented:
I removed the Undo.  Same Result.

I just checked and the Option Group is unbound.  Does that have any bearing on the issue?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
peter57rCommented:
Yes - in code you can't use .undo on an unbound field. (You might get away with sendkeys but that's not a good idea really.
You would need to set the value explicitly to option2.

0
 
wsturdevAuthor Commented:
I tried that.  I get an error -2147352567    The macro or function set to the BeforeUpdate or ValidationRule property for this field is preventing [My App Name] from saving the dat in the field.
0
 
peter57rCommented:
sorry - the alignment went a bit awry.
0
 
wsturdevAuthor Commented:
Excellent!  Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.