Cancel Change In Option Group

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a way to cancel a change in an option group? The option group still
changes to the option clicked on when clicking on the NO button with the
following code in the BeforeUpdate event of the option group.

If MsgBox("Change?", vbYesNo) = vbNo Then
Cancel = True
Me!optctrl.undo
End If

Thanks!
 
Is optctrl an option button?
If so, try undoing the option group instead of the button.

If the option group is bound to a field, you could also set it to its
OldValue, or Undo the form.
 
G,
The OptionGroup must be "bound" to a field. This code worked for me...
Private Sub optX_BeforeUpdate(Cancel As Integer)
If MsgBox("Change?", vbYesNo) = vbNo Then
Cancel = True
Me.optX.Undo '(notice the Me. not Me!)
End If
End Sub

--
hth
Al Campagna . Candia Computer Consulting . Candia, NH USA
Microsoft Access MVP
http://home.comcast.net/~cccsolutions

"Find a job that you love, and you'll never work a day in your life."
 
Thanks for the respone Allen.
Yes, optctrl is the option group not the button.
And the form is unbound, setting it to its OldValue raises Run-time error
'2115':
"The macro or function set to the BeforeUpdate or validationRule property
for this field is preventing Test from saving the data in the field".
 
Okay, that makes sense. OldValue doesn't apply to unbound controls.

It seems you have some code or a macro in the BeforeUpdate event of the
option group, or else you something in the ValidateRule of the option group.

Perhaps you are using the control's BeforeUpdate to make sure the user
chooses what you want? Cancelling this event would prevent the user from
leaving the control.
 
Thanks Again.

There is no code or macro , validaterule to this option group.
In fact I created new test form, with only one "group option" and 3 option
button in it. And the following before event of group option:
If MsgBox("Do you want to change the option?", vbYesNo) = vbNo Then
Cancel = True
Me.frmOptionGroup.Undo
End If

The purpose here is user should be allowed to change the option only if
choose yes in the popup message. other wise the option should not change.
Is this the way to achieve it?
 
Thanks Al Campagna.
It is not bound field.
Thanks Again.

In fact I created new test form, with only one "group option" and 3 option
button in it. And the following before event of group option:
If MsgBox("Do you want to change the option?", vbYesNo) = vbNo Then
Cancel = True
Me.frmOptionGroup.Undo
End If

The purpose here is user should be allowed to change the option only if
choose yes in the popup message. other wise the option should not change.
Is this the way to achieve it?
 
You lost me.

There is no code in the BeforeUpdate event of the option group.

But there is code in the "before event of the group option"?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top