Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Undo not working in BeforeUpdate for Option Group

Posted on 2007-10-15
7
Medium Priority
?
871 Views
Last Modified: 2013-11-27
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?
0
Comment
Question by:wsturdev
  • 4
  • 3
7 Comments
 
LVL 77

Expert Comment

by:peter57r
ID: 20077695
You shouldn't need the undo.

0
 
LVL 1

Author Comment

by:wsturdev
ID: 20077856
I removed the Undo.  Same Result.

I just checked and the Option Group is unbound.  Does that have any bearing on the issue?
0
 
LVL 77

Expert Comment

by:peter57r
ID: 20077974
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 1

Author Comment

by:wsturdev
ID: 20078745
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
 
LVL 77

Accepted Solution

by:
peter57r earned 2000 total points
ID: 20079098
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
 
LVL 77

Expert Comment

by:peter57r
ID: 20079104
sorry - the alignment went a bit awry.
0
 
LVL 1

Author Comment

by:wsturdev
ID: 20080349
Excellent!  Thanks.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
When we develop an application in Ms Access 2016 we should also try to protect the queries, macros and table links. I know I may not have a permanent solution but for novice users, they will not manage to break your application. Below is the detail …
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Suggested Courses

569 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question