DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: What's wrong with my cancelevent?

  1. #1
    Join Date
    Aug 2004
    Posts
    43,023

    What's wrong with my cancelevent?

    [Originally posted by Bernie Kozlowski]

    For the first two if statements, I want the me.str_situation to change back to the original value, using the cancel event.  This is not happening. If I change the situation to 2, I get the appropiate message, but the value of me.str_situation is now 2 and the program will not go on until the user puts a 3 back in me.str_situation.

    How can I stop the update?



    Thanks



    Private Sub str_situation_BeforeUpdate(Cancel As Integer)

    ' compare old value to new value here

    If gsituation = &quot;3&quot; And Me.str_situation <> &quot;3&quot; Then
    DoCmd.CancelEvent
    MsgBox &quot;You cannot change a union plan to anything else. You will need to delete the record and re-enter it&quot;

    ElseIf gsituation <> &quot;3&quot; And Me.str_situation = &quot;3&quot; Then
    DoCmd.CancelEvent
    MsgBox &quot;You cannot change the situation to a union plan. You will need to delete the record and re-enter it&quot;

    Else

    Other things happen here

    Endif

    End sub


  2. #2
    Join Date
    Aug 2004
    Posts
    43,023

    Re:What's wrong with my cancelevent?

    [Originally posted by Mike Lyons]

    Don't use CancelEvent. You see the Cancel argument in the event procedure's header? Set that to a non-zero (I like to set it to True).

    Then exit the Sub using Exit Sub.


    To set the str_Situation back to the previous value, try the following:

    str_situation.Undo


    Mike

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center