Cancel Change In Option Group

C

Corrine

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!MyOptionGroupName.Undo
End If

I also tried reversing the Cancel and Undo lines.

Thanks!

Corrine
 
R

rkc

Corrine said:
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!MyOptionGroupName.Undo
End If

I also tried reversing the Cancel and Undo lines.

Interesting. We are probably both missing something here, but the
following code shows the only way I can make this work:

'Form level private variable
private optionValue

Private Sub Frame6_Click()

If MsgBox("Change?", vbYesNo) = vbNo Then
Me!Frame6.Value = OptionValue
End If
optionValue = Me.Frame6.Value

End Sub

You would think you could use the Frame6.OldValue property
instead of a form level variable, but it's value is changed by the
time the frame's BeforeUpdate event fires.
 
T

Tony C

Hello Corrine

What you need to do is the following: -

1. Create a Public Variable "OldOptionNumber" as an
integer and another Public Variable MsgValue (do not
declare a type!!) I keep all of my public variables in a
module entitled "PublicVariables".
2. On the required Forms "On Open" Procedure, add the
following code: -

Me.MyOptionGroupName.Value = 1
OldOptionNumber = 1

3. On the option groups "On Click" event, add the
following: -
MsgValue= MsgBox("Change?", vbYesNo)
If MsgValue = vbYes Then
OldOptionNumber = MeMyOptionGroupName.Value
Exit Sub
End If
Me.MyOptionGroupName.Value = OldOptionNumber
End Sub

HTH


Tony C
 

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

Top