Results 1 to 3 of 3
  1. #1
    Abby is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2014
    Posts
    1

    Question Yes/No message box - undo on 'No' response

    Hi, I have a few fields on a database (which is used by a number of people) which keep getting accidentally altered - I would like to put in an 'after change' message box which would confirm whether the change was intentional, allow the change on a 'yes' response but undo the change on a 'no' so that the data had not been altered if the user didn't mean to. The bit I would be grateful for input/advice on is the undo function after a No response as at the moment that's the bit that isn't working!

    I have got as far as:

    Private Sub Text16_AfterUpdate()
    Dim lngValue As Long
    lngValue = MsgBox("Do you want to change the surname?", vbYesNo + vbQuestion, "Confirmation")
    Select Case lngValue
    Case vbYes = MsgBox("Thank you")
    Case vbNo = fn.Undo


    End Select
    End Sub

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Most of us use the before update event:

    http://www.baldyweb.com/BeforeUpdate.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,016
    As Paul said, for validation code you'd usually use the BeforeUpdate event. To validate that data has actually been entered in a given Control or Controls, you'd use the Form_BeforeUpdate event.

    To check data that has been entered in a Control, for appropriateness, or as in this case, where you want to verify that the change was intentional, and want the message to pop as soon as the data is changed, you'd use the BeforeUpdate event of that Control:

    Code:
    Private Sub Text16_BeforeUpdate(Cancel As Integer)
    
    Dim lngValue As Integer
    
    If Not Me.NewRecord Then
    
     lngValue = MsgBox("Do you want to change the surname?", vbYesNo + vbQuestion, "Confirmation")
    
      Select Case lngValue
    
       Case vbYes
      
        MsgBox ("Thank you")
    
       Case vbNo
    
        Cancel = True
        Me.Undo
    
      End Select
    
    End If
    
    End Sub

    I've included a check to only pop this message if the Record is not a New Record; no use in aggravating the users when entering data for the first time in a Record.

    The Control's AfterUpdate event fires too late to do this kind of thing; by the time it executes the Value is already committed and can't be undone.

    Also, you'd do well to get into the practice of giving your Controls significant names, such as txtSurname. You'll thank yourself, later, when you go to modify your app! Six months from now Text16 will mean nothing to you.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

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

Similar Threads

  1. Replies: 3
    Last Post: 06-20-2013, 12:16 PM
  2. MS Access Response Time Calculation Help
    By qcjustin in forum Programming
    Replies: 9
    Last Post: 12-13-2012, 10:58 AM
  3. Unbelievable Response from Access
    By whistler in forum Queries
    Replies: 10
    Last Post: 01-26-2012, 12:55 PM
  4. Often get no response from access
    By Grooz13 in forum Access
    Replies: 6
    Last Post: 08-13-2010, 10:51 AM
  5. Slow Database Response
    By Nixx1401 in forum Access
    Replies: 3
    Last Post: 02-25-2010, 11:09 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