Results 1 to 3 of 3
  1. #1
    tylerg11 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Sep 2011
    Posts
    200

    Confirm changes to only certain fields


    I would like to prompt the user to confirm if changes are intended for certain field(s). I am using the BeforeUpdate property of the fields I want prompts on. But I can't get the following code to work. If Yes is clicked, it should save, which it does. If No is clicked, it should revert to the previous value. Here's my code:

    Code:
        If MsgBox("Are you sure you want to update the First Name field?", vbYesNo) = vbYes Then
            DoCmd.Save
        Else
            DoCmd.CancelEvent
            Me.txtContactFirstName = Me.txtContactFirstName.OldValue
        End If

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  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,018
    First off, Access will not let you change the Value of a Control, in the Control's BeforeUpdate event, which you're attempting to do with this line:

    Me.txtContactFirstName = Me.txtContactFirstName.OldValue

    Attempting that will pop an Error.

    Secondly, DoCmd.Save does not save a Record, it saves Design Changes to an Object, in this case, it would save any Design Changes to the Form.

    Thirdly, the above is OK! You don't really need or want to save the Record, yet! You just don't want to revert back to the OldValue of the Control, unless the user clicks on No.

    So, lets move code to the AfterUpdate event of the Control, and only deal with the user clicking on No. See if this meets your requirement:
    Code:
    Private Sub ContactFirstName_AfterUpdate()
     If MsgBox("Are you sure you want to update the First Name field?", vbYesNo) = vbNo Then
       Me!ContactFirstName = Me.ContactFirstName.OldValue
     End If
    End Sub

    By the way, to force a Save of a Record, which is not needed, here, but which is needed, in some circumstances, you can either use

    If Me.Dirty Then Me.Dirty = False

    or

    DoCmd.RunCommand acCmdSaveRecord

    Linq ;0)>

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

Similar Threads

  1. Message Box to Confirm Update
    By MintChipMadness in forum Programming
    Replies: 2
    Last Post: 08-15-2012, 03:52 PM
  2. Replies: 1
    Last Post: 07-20-2012, 05:22 PM
  3. Confirm Data Changes, Yes/No/Cancel
    By Subwind in forum Code Repository
    Replies: 6
    Last Post: 05-30-2012, 09:41 AM
  4. Help to confirm if a bug (or not).
    By 245 in forum Access
    Replies: 18
    Last Post: 01-15-2012, 07:50 PM
  5. Confirm Changes in a Query
    By 161 in forum Queries
    Replies: 6
    Last Post: 03-11-2011, 10:51 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