Results 1 to 5 of 5
  1. #1
    mickelb is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2015
    Posts
    4

    Check form field edit before update

    I have a form bound to a table and need VBA to :

    1) Check if a text field (SURNAME) has been edited in the current record (key is MEMNO)
    2) If it has then present a Yes/No message box along th elines "You have just edited this field. Is this correct?"
    3) If No reset text field to original value and end the routine
    4) If Yes then save the updated value in the bound table and also update a second table with a SURNAME field for the record number (MEMNO) open in the form

    I won't place any of the failed code here, or it is likely to confuse matters, other than I have tried oldvalue and undo without success.



    I am looking at the Before Update event to run this routine.

    Any advice appreciated.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    in the form code, paste the code below at the very TOP.
    the MV.. variable will capture the original value, the BEFOREUPDATE event will decide to keep it.

    Code:
    Private mvSurnameOrig
    
    
         'capture the original value
    Private Sub SURNAME_GotFocus()
    mvSurnameOrig= SURNAME 
    End Sub
    
    
    Private Sub Addr_BeforeUpdate(Cancel As Integer)
    If SURNAME <> mvSurnameOrig Then
      If MsgBox("You have just edited this field. Is this correct?", vbQuestion + vbYesNo, "Accept") = vbNo Then
         Cancel = True
         SendKeys "{ESC}"
      End If
    End If
    End Sub

  3. #3
    JamesDeckert is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jul 2015
    Location
    Salina, KS
    Posts
    262
    @ranman
    shouldn't "SURNAME = mvSurnameOrig" instead be "mvSurnameOrig = SURNAME"
    also shouldn't the Addr_BeforeUpdate be SURNAME_BeforeUpdate

  4. #4
    mickelb is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2015
    Posts
    4
    Thanks for replies.

    @ranman

    Is this code the Before Update event for the SURNAME field?
    Private Sub Addr_BeforeUpdate(Cancel As Integer)
    If SURNAME <> mvSurnameOrig Then
    If MsgBox("You have just edited this field. Is this correct?", vbQuestion + vbYesNo, "Accept") = vbNo Then
    Cancel = True
    SendKeys "{ESC}"
    End If
    End If
    End Sub

    What event does this code go in?:
    Private mvSurnameOrig


    'capture the original value
    Private Sub SURNAME_GotFocus()
    SURNAME = mvSurnameOrig
    End Sub

    I can't get it to work if I put the latter in the On Open event for the form - Invalid Attribute in Sub or Function with Private highlighted

  5. #5
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    but yes
    mvSurnameOrig =SURNAME

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

Similar Threads

  1. Replies: 18
    Last Post: 06-20-2014, 12:13 PM
  2. Replies: 3
    Last Post: 02-05-2014, 04:01 PM
  3. Replies: 0
    Last Post: 03-13-2012, 12:57 PM
  4. Trouble with check if Exists before Edit or Add Record
    By mrfixit1170 in forum Programming
    Replies: 4
    Last Post: 02-10-2012, 10:38 AM
  5. Replies: 1
    Last Post: 08-11-2011, 11:42 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