Results 1 to 8 of 8
  1. #1
    ironfelix717 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2018
    Posts
    150

    Option Group Control: Cancel click / update event

    Hello,


    I am looking to find a simpler solution to "canceling" an update/click event of an Option Group control.

    The option group is used only to set a tab control's value and display the correct page in the tab control.
    The option group is a series of buttons that display a tab window page.



    For example....

    Code:
    Private Sub OpGroup_AfterUpdate()
    
    TabCtl = OpGroup. 'show the correct page
    
    
    End Sub

    However, in this routine, if I want to cancel this action,
    there is no way to "fully" cancel.
    For example....

    Code:
    Private Sub OpGroup_AfterUpdate()
    
    If SomeFunction() = true
    
    TabCtl = OpGroup. 'show the correct page
    
    Else
    
    'CANCEL!
    End if
    End Sub
    The above will obviously not switch the tab control.
    However, it will still change the Option Group control's value. I would like it to not change in this case and revert or remain to its original selection, should 'SomeFunction()' be false.

    The only way to simulate this behavior (that I have found) is to go back and find the original option group button, based on the tab control and re-select it. This usually is done with a loop through the option group's controls collection, which albeit small, is ineffecient.

    Does anyone else have a suggestion?



    Thanks

  2. #2
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,411
    Check out the oldvalue property. Maybe your cancel code can set it back to that value.

  3. #3
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    My suggestion would be BeforeUpdate, not AfterUpdate. As a general principle, never use AfterUpdate when you want to prevent code from affecting object to which the event applies. It's too late.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    ironfelix717 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2018
    Posts
    150
    Quote Originally Posted by Micron View Post
    My suggestion would be BeforeUpdate, not AfterUpdate. As a general principle, never use AfterUpdate when you want to prevent code from affecting object to which the event applies. It's too late.

    Hi,

    Yeah, even BeforeUpdate does not afford this functionality. It's 'cancel' event argument is just as worthless as the option group's 'Old Value' property. Old Value is used in bound situations, which this is not.

    Thanks

  5. #5
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,411
    Try this method. Option group on_enter stores the value in a module variable.
    Click another option. Typing "Reset" in the tbText will reset the option to the stored value.
    Code:
    Option Compare Database
    Option Explicit
    Dim nPrev As Integer
    
    
    Private Sub OpGroup_Enter()
        nPrev = Me.OpGroup.Value
    End Sub
    
    
    Private Sub tbText_AfterUpdate()
        If Me.tbText = "Reset" Then
            Me.OpGroup.Value = nPrev
        End If
    End Sub

  6. #6
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    I should have realized your frame was unbound. Post the code so we have a clue as to what the sequence/process is. There's probably a hack that can be devised using mouseup and a function.

    Alternatively, you could just have a table with one field for the frame value. You wouldn't use the value as meaningful data but it would probably make the BeforeUpdate event or OldValue properties useful.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    A frame is null when you first enter it so your module level variable should be a variant for that approach to work all the time, or you'd have to convert the null. Frame enter event could run 2 ways that I can think of:
    1) if the frame and the group are the only controls that can be entered on the form (will occur on form open) or
    2) if you can tab into the frame and enter it
    - either case happening before an option has been selected. Otherwise I think that would work.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  8. #8
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    How is the value of the OG initially set? is there a default value?
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Option Group Control using Row source data
    By Tuckejam in forum Forms
    Replies: 2
    Last Post: 04-09-2020, 11:17 AM
  2. Replies: 2
    Last Post: 03-17-2016, 04:52 PM
  3. Replies: 6
    Last Post: 12-04-2013, 07:00 PM
  4. Update query with Option Group Value
    By bcofie in forum Access
    Replies: 6
    Last Post: 08-08-2012, 02:51 PM
  5. tab control - firing a page on-click event
    By Chuck55 in forum Programming
    Replies: 7
    Last Post: 05-01-2012, 09:57 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums